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,
};