Temp table in LINQ to Entities

I have a user id table that is huge.
I have a set of user IDs that I want.
I have two tables with a user foreign key key.

What is the best way to get this information? "

Ideally, in SQL, the end result would be something like this (zero values ​​if there is no user ID in one table and not another):

userid  table1value table2value
1        null          12
5        123           null
+3
source share
3 answers

, , , , ( ), O LINQ to SQL , LINQ, =). , , , , .

, . .

+1

, LINQ to Entities " "... , LINQ .

, proc proc , proc. Proc .

.

+2

, LINQ () , SQL, SQL-, Entity Framework. :

var results = from u in UserDataSource
   join t1 in Table1DataSource on u.UserId = t1.UserId into gj
   from jt1 in gj.DefaultIfEmpty()
   select new {u.UserId, Table1Data = jt1 == null ? String.Empty : jt1.Data};

If the tables are really huge or there is additional processing to execute the result, I would think about creating a view on the server and map it to the code Entity. Then it becomes a very simple choice; you just filter the view results for the user IDs you want to see.

+1
source

Source: https://habr.com/ru/post/1773142/


All Articles