Get unrelated objects in one trip to the database

I have 3 objects that are not related to each other, and I want all these entities to be on the same trip to the database, how can I do this?

thanks

+4
source share
3 answers

You can do it with

var result = from foo in ctx.Foos from bar in ctx.Bars where foo.id == xxx && bar.id == yyy select new { Foo = foo, Bar = bar}; 

This will give you the specific foo and panel in the same request. Although, this will lead to the creation of a rather inefficient SQL, so I would not recommend it.

0
source

You can use the Future Query extension method. This link can do the job as needed.

+1
source

If you are retrieving data from a pure relational database, you should see if you can get multiple result sets in a single query. Alternatively, if you can get dangling results, extract them in a tree structure with the appropriate shape.

If your database connection is not enough for this, you can use the universal join of the results and then return the join query marked in some form to determine which result is from which table.

You did not specify a reason for decreasing rounding, but you can also use something like a stored procedure to collect the necessary data on the server and then return it to a single result set.

0
source

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


All Articles