The Select clause and SelectMany() method both are used to produce a result value from a source of values. The difference lies in the result set. The Select clause is used to produce one result value for every source value. The result value is a collection that has the same number of elements from the query. In contrast, the SelectMany() method produces a single result that contains a concatenated collection from the query.
Friday, May 3, 2013
What are the advantages of LINQ over Stored Procedures?
Below is the three advantages of LINQ over stored procedures.
Debugging - As debug point concern, as LINQ is part of .NET, we can use the visual studio's debugger to debug the queries but it is tough to debug the Stored procedure as it will not support the visual studio debugger.
Deployment - In case of deployment, we need to provide an additional script for stored procedures to execute but in case of LINQ, it will complie into single DLL hence deployment becomes easier.
Type Safety - As LINQ is type safe, the queries errors are type checked at compile time. Better suggest to use LINQ because it helps to encounter an error at the compile time rather than at runtime exception.
Debugging - As debug point concern, as LINQ is part of .NET, we can use the visual studio's debugger to debug the queries but it is tough to debug the Stored procedure as it will not support the visual studio debugger.
Deployment - In case of deployment, we need to provide an additional script for stored procedures to execute but in case of LINQ, it will complie into single DLL hence deployment becomes easier.
Type Safety - As LINQ is type safe, the queries errors are type checked at compile time. Better suggest to use LINQ because it helps to encounter an error at the compile time rather than at runtime exception.
IEnumerable & IQueryable pros &Cons
IEnumerable
Pros
1. The most generic item of all.
2. Still might use deferred execution.
3. IEnumerable is best suitable for working with queries later on. It helps best when we try to add more queries with our previous one and we do not want to run our previous query in realtime but when we requested it or iterated through those or finally passing as a .ToList() object .
4. IEnumerable does not run query until it is requested by iteration.
Cons
1. IEnumerable doesn’t move between items, it is forward only collection as LinkedList. You can't get at "item 4" without passing items 0-3.
2. Read-only list, you can't add to it or remove from it.
3. Actually the model binder is not able to bind an enumerable because it is a too generic Interface, and it is not able to choose a concrete class to create that implements the IEnumerable.
IQueryable
Pros
1. Query isn't executed until to really iterate over the items, maybe by doing a .ToList()
2. IQueryable best suits for remote data source, like a database or web service. IQueryable is a very powerful feature that enables a variety of interesting deferred execution scenarios (like paging and composition based queries).
Cons
1. avoid passing IQueryable to Views
2. It is not a good place to handle errors...so better getting rid of delayed execution before passing to Views.
Into and Let in LINQ ( Let vs. Into)
Into
The
var em = from e in emp
group e by new{ e.DeptId}
into gEmp
where gEmp.Count() > 1
select new { gEmp.Key.DeptId, salary = gEmp.Sum(t => t.Salary) };
In the above query, after applying
Note:
var em = from e in emp
group e by new { e.Salary, e.Id }
into gEmp
let avgsal = (gEmp.Sum(t => t.Salary) / gEmp.Count())
where gEmp.Key.Salary == avgsal
select new { gEmp.Key.Salary, gEmp.Key.Id };
The above query is used to find out employee(s) having salary more than
The
Into keyword allows creating a temporary variable to store the results of a group, join, or select clause into a new variable.var em = from e in emp
group e by new{ e.DeptId}
into gEmp
where gEmp.Count() > 1
select new { gEmp.Key.DeptId, salary = gEmp.Sum(t => t.Salary) };
In the above query, after applying
into on grouping, it creates a IGrouping type gEmp variable, which is used to apply the next filter.Note:
Into is used when you want to perform an operation on grouped data.Let
TheLet keyword allows storing the results of a query which can be used in a subsequent query; i.e., it creates a new variable and initializes it with the result of the expression you supply.var em = from e in emp
group e by new { e.Salary, e.Id }
into gEmp
let avgsal = (gEmp.Sum(t => t.Salary) / gEmp.Count())
where gEmp.Key.Salary == avgsal
select new { gEmp.Key.Salary, gEmp.Key.Id };
The above query is used to find out employee(s) having salary more than
avgSalary. The Let keyword allows to create a new variable avgsal that is used in further operations.Let vs. Into
Most people find it difficult to decide which one to use when designing a LINQ query.Into– Hides the previous variable when used in a query, as you see in the above example. Which means its hides the previous range variable and creates a temporary range variable which you can use in further operations.Let– Doesn’t hide the previous variable and creates a new variable. Which means you create a new variable and you can also use the previous variable, so you can use both in further operations.
Friday, April 19, 2013
how can i pass value from master page to content page and vice versa ?
//on master pag
Label lbl =(Label) Page.Master.FindControl("ContentPlaceHolder1").FindControl("lblm"); lbl.Text =
"hgfgc";//lbm label on aspx pages within ContentPlaceHolder1 id
//how can i pass value from content page to master page ?
//on aspx pages
Label lbl = (Label)this.Master.FindControl("lblm");lbl.Text =
"hgfgc";
//lbm lable on master pages
Label lbl =(Label) Page.Master.FindControl("ContentPlaceHolder1").FindControl("lblm"); lbl.Text =
"hgfgc";//lbm label on aspx pages within ContentPlaceHolder1 id
//how can i pass value from content page to master page ?
//on aspx pages
Label lbl = (Label)this.Master.FindControl("lblm");lbl.Text =
"hgfgc";
//lbm lable on master pages
Thursday, April 18, 2013
Passing string values into SQL query via parameter
CREATE PROC S_Test
(
@params varchar(100)
)
AS
SET NOCOUNT ON
DECLARE @sql as NVARCHAR(4000)
SET @sql = 'select count(*) from
myTable where myColumn in (' + @params
+ ')'
EXEC sp_ExecuteSQL @sql
GO
Template OF Cover Letter
Dear Sir/Madam,
This mail is to express my interest in the post of Software Testing Engineer in your company. I believe that my strong technical experience and education will make me a very competitive candidate for this position.
I hold a Degree in Bachelor of Technology (Information Technology) from Ghaziabad and I had a total working experience of 4 Years and 10 Months. I have an experience of all the different testing phases in the software lifecycle and good working knowledge of taking a project from the initial requirement stage to the final release stage. I had done Test Planning and also created Test Planning & Strategy documents. I am confident that my presentation skills and high quality and cost effective methodologies can secure big projects for the company.
I assure you that my knowledge and experience will help me to serve the organization in the best possible ways.
I am enclosing my resume for your perusal and looking forward to hear from you soon.
Thanking You,
Yours sincerely,
This mail is to express my interest in the post of Software Testing Engineer in your company. I believe that my strong technical experience and education will make me a very competitive candidate for this position.
I hold a Degree in Bachelor of Technology (Information Technology) from Ghaziabad and I had a total working experience of 4 Years and 10 Months. I have an experience of all the different testing phases in the software lifecycle and good working knowledge of taking a project from the initial requirement stage to the final release stage. I had done Test Planning and also created Test Planning & Strategy documents. I am confident that my presentation skills and high quality and cost effective methodologies can secure big projects for the company.
I assure you that my knowledge and experience will help me to serve the organization in the best possible ways.
I am enclosing my resume for your perusal and looking forward to hear from you soon.
Thanking You,
Yours sincerely,
Subscribe to:
Posts (Atom)