Click here to Skip to main content
15,887,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two tables in a database what i want to combine and work with that data.

So i used that codesnippet:
C#
var listOfFoundRespIds = (from a in context.Adresses
						  join e in context.ExtraData
							  on a.LFD equals e.lfd
						  where a.PROJID == 2048
						  select new
						  {
							  RESPID = e.str03,
							  LFD = e.lfd,
							  PROJID = a.PROJID
						  })
						  .ToList();


The database table itself has 31.966.037 entries.
While debugging (directly after code execution) i started the iEnumeration Viewer and looked into context.Adresses and done a csv export. There was 995.101 entries in that list. So at execution time i dont have all entries from the main table to work with it.

Maybe anyone has any idea, how to get fixed?

What I have tried:

Checked IEnumeration Viewer and csv checkout
Double check databasetable
Read docs about Entity Framework and other SQL Stuff.
Posted
Comments
PIEBALDconsult 22-Dec-23 11:25am    
I doubt you actually need to have all of those items in memory all at once.
Sascha Manns 22-Dec-23 13:50pm    
I misunderstood the whole process. I thought it gets all entries from database and does the join in the memory of my machine. But the returned 995.101 entries are exactly that entries after merge and filtering. So that is what i need. :-)

1 solution

You are performing an INNER JOIN - you will only get back results from the Addresses table which have a corresponding record in the ExtraData table.

If you want all records from the Addresses table, even if they have no corresponding record in the ExtraTable, then you need to perform a LEFT JOIN.

Perform left outer joins (LINQ in C#) - C# | Microsoft Learn[^]

C#
from a in context.Adresses
join ed in context.ExtraData on a.LFD equals e.lfd into edg
from e in ed.DefaultIfEmpty()
where a.PROJID == 2048
select new
{
    RESPID = e.str03,
    LFD = e.lfd,
    PROJID = a.PROJID
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900