LINQ Usage Notes

Source: Internet
Author: User

How do I use Between...and in LINQ?
var  from inch context. Parent            from in context. Child.where (x = P.cob >= x.effective)                                   = P.cob <= x.expiry)                                   . DefaultIfEmpty ()            group p by P.cob into PG            Selectnew            {              = pg. Key,              = pg. Count ()            };

The following is a multiple where condition to handle the Between...and, but an inner join.

var  from inch Appointments                          from inch Properties                          from inch Clients                         where a.id = =                        p.oidwhere a.start.date >=                        startdate.date where a.start.date<=enddate.date

How to use in?

varAllowedstatus =New[]{"A","B","C" };varfilteredorders = orders. Order.where (o =allowedstatus.contains (O.statuscode));
orinchquery Syntax:varFilteredorders = fromOrderinchorders. OrderwhereAllowedstatus. Contains (Order. StatusCode)SelectOrder
How to use multiple connection conditions Join...on?

varquery = fromObj_iinchSet1join Obj_jinchSet2 onNew{JoinProperty1=Obj_i.somefield1, JoinProperty2=Obj_i.somefield2, JoinProperty3=obj_i.somefield3, JoinProperty4=obj_i.somefield4} equalsNew{JoinProperty1=Obj_j.someotherfield1, JoinProperty2=Obj_j.someotherfield2, JoinProperty3=obj_j.someotherfield3, JoinProperty4=Obj_j.someotherfield4}
Http://stackoverflow.com/questions/3020442/linq-joining-in-c-sharp-with-multiple-conditions

If you want to achieve the effect of this SQL:

SELECT *  from table1 a  Left JOIN  on =  and  = and <= and = 0 ;

Can do this:

varquery = ( fromXinchcontext.table1 Join yinchContext.table2 onNew{Key1=X.col1, Key2=x.col2 Key3=true, Key4=true} equals {Key1=B.key1, Key2=B.key2, Key3= b.from_date<DateTime.Now, Key4= !b.deleted} into result fromRinchresult. DefaultIfEmpty ()Select New{x.something, r.something}
Http://stackoverflow.com/questions/7765230/linq-to-entity-multiple-join-conditions
How to use group ... by group?

such as SQL:

SELECT *  from < TableName>GROUPby<Column1>,<Column2> 
Group  by  = = new {x.column1, x.column2})
var query = ( from in transactions             new  {t.materialid, T.productid } into             grp                    Selectnew                    {                        grp. Key.materialid,                        Grp. Key.productid,                        = grp. Sum (t = = t.quantity)                    }). ToList ();

LINQ Usage Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.