What can I use instead of Include?

Is there an alternative to using Include for loadable objects?

The reason I can't use Include is because it is case sensitive.
Consider the following example:
I have two tables:

enter image description here

enter image description here

Pay attention to the difference in the case.

When I want to receive a Sager Stamkartotek load, I use Include , but Include does not load Stamkartotek :

enter image description here

** Update 1 **

I noticed this strange behavior - if I use any fields from Stamkartotek , it connects correctly: enter image description here

But if I go and get only the value Stam_nr instead of the whole object - it gives me A instead of A :

enter image description here

Research so far:

  • The EF team is aware of this problem - but decided not to fix it.
  • This guy has the same problem only using code-one - no solution found

Update 2
SQL created using Include :

 FROM [dbo].[Sager] AS [Extent1] INNER JOIN [dbo].[Stamkartotek] AS [Extent2] ON [Extent1].[Klient_Stam_nr] = [Extent2].[Stam_nr] WHERE 'jek15' = [Extent1].[Sags_nr] 

Update 3
By loading them into individual requests and letting changetracker fix the link. It doesn't work either:
enter image description here

+6
source share
3 answers

Create a view with LOWER around foreign keys to ensure that reads always return the same case in EF.

And insert and delete using stored procedures

You can track and vote on the issue that will be addressed here:

Differences in string comparisons between .NET and SQL Server cause problems for resolving FK relationships in State Manager

+3
source

I don't have all the information in this case, I think you need to update the relation of your table using whole keys to make the ratio.

When using linq, the query will be executed in the database when calling ToList () or First, for example. If you use Include, the query will load the data when any of these actions are called.

The problem is with A or it could be a matching situation, check your configuration, some sorting ignores the data case.

I suggest: Update the tables that you use with integer keys, and use the left outer join if you want to load related data. Sometimes it's better to use the good old tsql (you can also make a left outer join in linq).

+1
source

Instead of using .Include you can load objects in separate requests. Change tracker will establish relationships for related objects that it is already tracking, and if you get your requests correctly, you should get a solution that, in terms of functionality, is equivalent to using .Include .

+1
source

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


All Articles