EF Left Connection

Source: Internet
Author: User
Tags sort

1

var alist = menu. Getpagedlist (page, limit, out totalcount, filter, by). ToList (); Set 1
var blist = menu. GetAll (). ToList (); Set 2
var data = from A in alist
           joins B in blist on A.menuparentid equals b.id to temp from
           BB in temp. DefaultIfEmpty ()
           select New
           {
               id=a.id,
               menuName = a.menuname,
               Menuicon = A.menuicon,
               Menuparentid = A.menuparentid,
               menuurl = A.menuurl,
               menudescription = a.menudescription,
               sort = a.sort, state
               = a.state,
               createtime = A.createtime,
               updatetime=a.updatetime,
               parentname = BB = = null? "": Bb.menuname//Pay special attention to whether this BB is a null condition
           };
var list = data. ToList ();

Note: The defaultifempty operator is used in the previous example to provide a default element for the real sequence. DefaultIfEmpty uses the default keyword in generics. The default keyword returns null for reference types, and 0 for value types. For struct types, they are initialized accordingly to null (reference type) or 0 (value type) according to their member type


We can not use default, but in order to defaultifempty the value of the object when the null is given. The statements are as follows:

The left join, when empty, uses the default object
var leftjoinquery =  s in db. Student
join C in DB. Course on
s.coursecno equals C.CNO to GC from
GCI in GC. DefaultIfEmpty (
new Course {Cname = "", cperiod= ""}     //set to NULL when default value
)
select New
{
    ClassID = S. Coursecno,
    ClassName = GCI. Cname,
};


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.