c# - Entity Framework nesting variables -
i have following setup in entity:
public class t_ht { public int unid { get; set; } public string name { get; set; } public icollection<t_htc> comments { get; set; } }
and
public class t_htc { public int unid { get; set; } public int htid { get; set; } [foreignkey("htid")] public t_ht ht { get; set; } public int cid { get; set; } [foreignkey("cid")] public t_c c { get; set; } }
and
public class t_c { public int unid { get; set; } public string name { get; set; } public icollection<t_htc> comments { get; set; } }
where relationships follows:
many t_htc
1 t_ht
one t_ht
many t_htc
and
many t_htc
1 t_c
one t_c
many t_htc
this setup works fine , achieves need.
however, when querying using c#
, linq/entity
can following:
var queryht = context.ht.include(x => x.htc);
and
var queryc = context.c.include(x => x.htc);
either of these return single t_ht
nested list of t_htc
or single t_c
nested list of t_htc
however, want achieve is:
a single t_ht
, nested list of t_htc
, , t_htc
include corresponding entry in t_c
i know can achieve performing join joins queryc
queryht
seems bit of long way go doing this.
surely entity can achieve trying do?
please note variable names have been adjusted purpose of question, , not in actual code.
you can achieve want this:
var queryht = context.ht.include("htc.c");
var queryht = context.ht.include(x => x.htc.select(y => y.c));
the strong typed version requires adding using system.data.entity;
.
Comments
Post a Comment