none
lazyloading proxy for POCO entity RRS feed

  • Question

  • I have a result set from my DB that's getting materialized into a POCO type I've defined. I want to start making navigation properties based on the foreign keys I have in my result. The entities that are navigation properties are in my csdl, mapped to tables.  Ideally, I would like to have the framework use a LazyLoading proxy to populate these properties so I don't have to have a lot of boilerplate code in my class files.

    Here's the catch: since my entity is Translated into the context from a stored procedure I don't have mapping in my edmx/csdl. So the proxy doesn't get generated. But if I decide to add mapping, it errors out with "3027: Mapping not found." Obviously I need to be mapping to some store regardless.

    Also, before I go down this path, if I call LoadProperty to eagerly load, having decorated my navigation property with the [ForeignKey] annotation, will that work without any mapping? I suppose I can work around by doing that but again, it's kind of messy.

    Update: It doesn't look like I can do eager loading since the "entity" is detached and not able to be added to the context unless it's mapped. I guess my question now is, is there any way I can get a strongly-typed stored procedure result with navigation properties or properties that are entities/collections of entities? Complex types aren't really an option since you can't really have relational properties on them.

    Wednesday, July 6, 2011 9:44 PM

Answers

  • Hello,

    you can't unless you have fully mapped entity in your model. Lazy loading and loading navigation properties work only for entities. Your stored procedure must return an entity. That means you must cheat EF and either create dummy table in your database with all the properties and relations you need and import this table (after that you can delete it) with a wizard or you must modify whole edmx manually (including SSDL and MSL). In either case once you do it you cannot use Update from database any more.

    Best regards,
    Ladislav

     

    • Marked as answer by j-simms Friday, July 8, 2011 2:43 PM
    Thursday, July 7, 2011 9:22 AM

All replies

  • Hello,

    you can't unless you have fully mapped entity in your model. Lazy loading and loading navigation properties work only for entities. Your stored procedure must return an entity. That means you must cheat EF and either create dummy table in your database with all the properties and relations you need and import this table (after that you can delete it) with a wizard or you must modify whole edmx manually (including SSDL and MSL). In either case once you do it you cannot use Update from database any more.

    Best regards,
    Ladislav

     

    • Marked as answer by j-simms Friday, July 8, 2011 2:43 PM
    Thursday, July 7, 2011 9:22 AM
  • Okay, thank you, that's what I was afraid of.
    Friday, July 8, 2011 2:42 PM