Is EF 4.1 totally unsuitable for hierarchical operations? RRS feed

  • Question

  • Hi,

    I'm getting the feeling that the code-first approach is totally unsuitable for hierarchical data structures.

    First of all, since EF does not have support for hierarchyid data type (which is very strange, since it is CLR based type), so all that left is to use "ParentId -> Id" self-referencing data structures. But even then, since the only way to express recursive queries is by using CTE's, the lack of support for SP's preventing this option as well, since the code-first approach will destroy all the SP's on every change of the module.

    So far, my conclusion so far is that it is impractical to use the code-first approach with hierarchical data structures.

    Since generally i like the concept of code-first very much, my question is did i overlooked something?

    Sunday, July 24, 2011 12:34 PM

All replies

  • You can use Stored procedures with Code first like so 

    IEnumerable<MyEntityType> customers =   ((IObjectContextAdapter)this)  .ObjectContext.ExecuteStoreQuery<Customer>("GetEntity");
    Which would allow you to load these objects but you will have issues persisting them. I don't think that this has been address yet, but I would keep looking for it in later releases.

    Devlin Liles http://twitter.com/devlinliles http://www.devlinliles.com/ If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Sunday, July 24, 2011 1:03 PM
  • I didn't say that this is impossible, i'm saying, it's very unconvenient hence - impractical. If i don't have a way to persist the SPs, code-first becomes very unproductive workflow.

    Sunday, July 24, 2011 1:44 PM