简体   繁体   中英

C# forming Linq Query using .FindByExp

Table 1

Id    Name
1     Tank 1
2     Tank 2
3     Tank 3
4     Tank 4

Table 2

Id   Name
1    Tank 1
2    Tank 2

Result List it should return

Id    Name
1     Tank 1
2     Tank 2
3     Tank 3
4     Tank 4

I need to form a linq query using.FindByExp only. Like below i need to use joins and arrive at above list Result.

var tankLst = context.Tank.FindByExp(a => a.Id== S.Id).ToList();
var distinctNames = context.Table1.FindAll().Select(x=>x.Name).Distinct().ToArray();
var tab1 = context.Table1.FindAll().ToList();
var tab2 = context.Table2.FindAll().Where(x=> !distinctNames.Contains(x.Name)).ToList();
var resultList = tab1.Concat(tab2).OrderBy(x=>x.Name);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM