LINQ To Entities and Lazy Loading

前端 未结 6 1642
谎友^
谎友^ 2020-12-28 23:45

In a controversial blog post today, Hackification pontificates on what appears to be a bug in the new LINQ To Entities framework:

Suppose I search fo

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 00:32

    Having lost a few days to this very problem, I sympathize.

    The "fault," if there is one, is that there's a reasonable tendency to expect that a layer of abstraction is going to insulate from these kinds of problems. Going from LINQ, to Entities, to the database layer, doubly so.

    Having to switch from MS-SQL (using LingToSQL) to MySQL (using LinqToEntities), for instance, one would figure that the LINQ, at least, would be the same if not just to save from the cost of having to re-write program logic.

    Having to litter code with .Load() and/or LINQ with .Include() simply because the persistence mechanism under the hood changed seems slightly disturbing, especially with a silent failure. The LINQ layer ought to at least behave consistently.

    A number of ORM frameworks use a proxy object to dynamically load the lazy object transparently, rather than just return null, though I would have been happy with a collection-not-loaded exception.

    I tend not to buy into the they-did-it-deliberately-for-your-benefit excuse; other ORM frameworks let you annotate whether you want eager or lazy-loading as needed. The same could be done here.

提交回复
热议问题