Suresh Behera

The Microsoft .Net Junkies

News

Blogroll

Reading

April 2011 - Posts

Easy way to write WHERE IN clause in Linq

I found many links to write IN clause in Linq but following is the simplest way achieve this

public IEnumerable<Products> GetProductsByIds(List<int > ids)
{
    from id in Products
    where (x => ids.Contains(x.Id))
    select new {x.Id, x.ProductName};
}

var productids = new List<int> { 33,34,35,36 };

GetProductsByIds(productids);

 

Happy Coding..!

Suresh Behera

Posted: Apr 29 2011, 02:54 PM by Suresh Behera | with 1 comment(s) |
Filed under: ,
Converting SQL To Linq

After working so long on I SQL ,you always need little trick to write you Linq Quires.Here is few tools which might help to generate your linq quries.

SQL to LINQ converter
http://www.sqltolinq.com/

Code Generation in LINQ to SQL
http://msdn.microsoft.com/en-us/library/bb399400.aspx

LINQPad : Code generation for Linq
http://www.linqpad.net/

Converting SQL to LINQ
http://blogs.msdn.com/b/vbteam/archive/tags/converting+sql+to+linq/default.aspx

101 LINQ Samples
http://msdn.microsoft.com/en-us/vcsharp/aa336746

Thanks,

Suresh Behera

Posted: Apr 29 2011, 02:08 PM by Suresh Behera | with no comments |
Filed under: ,
101 LINQ Samples

Awesome list of LINQ sample

Restriction Operators
Projection Operators
Partitioning Operators
Ordering Operators
Grouping Operators
Set Operators
Conversion Operators
Element Operators
Generation Operators
Quantifiers
Aggregate Operators
Miscellaneous Operators
Custom Sequence Operators
Query Execution
Utility Routines
Join Operators

 

Thanks,

Suresh Behera

Posted: Apr 13 2011, 11:37 AM by Suresh Behera | with 2 comment(s) |
Filed under: ,
More Posts