I have a simple parent child relationship that I want to load from LINQ to SQL. I want to load the children in the form of parents at the same time. The generated SQL is working very well, it is trying to connect with the children as well as counting them. I will not update these items. I will not add children to parents. I am interested only to read. I have simplified tables to bare minimum. In fact, I have more columns, SQL is generating the following SQL from LINQ
SELECT [t0]. [Pant ID] AS [ID], [T.] [Name], [t1]. [Childbed] AS [ID2] [T1]. [Parent], [t1]. [Name] AS [Name 2], SELECT COUNT (*) FOr [DBO]. [Lynchild] AS [T2] where [T2]. [Pant ID] = [T0 [PantID]) AS [Value] [DBO]. [Linqparent] AS [T] LEFT OUTER JOIN [DBO]. [Linqchild] AS [T1] O [T1]. [Pentid] = [t0]. [Parent] by ORDER [T.] [Parent], [t1]. [Child id] I do not know why SELECT COUNT (*) ... is there but it will run away. There will be millions of rows in production both in both parents and child tables. There is a huge amount of time spent in additional queries, it seems unnecessary, is there any way to remove it? I'm also not sure whether the ORDER BY is coming from either. Classes look like this. <[P>
[table = name ("name =" Dbo.linqparent "]] public class LinqParent {[column (name =" parent ID ", autosink = autosyncon insert, ipramerica = true, ISDB generated = true, canbul = False)) Public Login ID {Received; Set; } [Column (name = "name", cannabul = false)] The name of the public string {get; Set; } [Association (Others = "ParentID", it's KY = "ID", ICEIREGNE = true)) Public InenMeBable & lt; LinqChild & gt; Children {receive; Set; }} Public class LinqChild {[column (name = "hair id", autosink = autosyncon insert, imperial = true, isdb generated = true, canbul = false)) public long id { get; Set; } [Column (name = "parent", canbull = false)] public long parent ID {received; Set; } [Column (name = "name", cannabul = false)] The name of the public string {get; Set; }} I am using something like the following like a query, there will be a production where it matches and which matches. New data syntax (new database stringfender). Connection string, new attribute mappingsource ()) {objecttracking = false = defrade loading} = photi}} {var load option = new data load Option (); LoadOptions.LoadWith & lt; LinqParent & gt; (F = & gt; F.Ceds); Context.LoadOptions = loadOptions; Var table = reference GetTable & lt; LinqParent & gt; (); Context.log = console.aut; // do something with the table}
Unfortunately, no. ORMs are not the most unbiased solutions; If you write your own SQL (or use of stored procedures), you'll always get a better performance, but it prepares that toddolf.
What you see is standard practice with ORM; Rather than using a multiple result query (which is the most effective way of me, but I am not an ORM library author), instead of using ORM, the entire graph will level the entire graph in a single query and all It is also that where the ORDER BY arrives, the information is needed - it helps in determining information which are duplicating the data bits. , because it requires that the linked bodies will be in the connective block.
Comments
Post a Comment