Monday 15 September 2014

linq to entities - Entity Framework 6 and explicit loading a graph of objects -



linq to entities - Entity Framework 6 and explicit loading a graph of objects -

i have model construction :

public class blog { public icollection<post> posts { get; set; } } public class post { public icollection<comment> comments { get; set; } } public class comment { }

i explicitly load "posts" , "comments" collections.

i can not use lazy loading nor eager loading (using include operator) because loaded collections have filtered before loaded each object (as may contain huge amount of items).

any advice on best manner accomplish ?

thanks !

riana

i found solution inspired , based on this rowan miller's presentation @ teched 2014.

my main concern able filtered out "posts" , "comments" collections (according known conditions) when load blog aggregate.

lazy loading not solution send much query database in order load needed posts , corresponding comments (posts , comments collections can huge)

i thought eager loading, using "include" operator, not solution because "include" operator not back upwards filter. means if load blogs : mycontext.blogs.include("posts"), posts collection not filtered , posts database loaded, don't want that.

in ef6, possible intercept , modify queries before interepreted sql , sent database. feature key solution.

my solution intercept select queries on post , comment objects , modify them apply filters. implementation, can eager loading , still select queries on post , comment object have filters applied automatically.

rowan miller demonstrate feature implementing soft delete.

hope help,

riana

frameworks linq-to-entities entity loading

No comments:

Post a Comment