none
POCO mapping and namespaces (Entity Framework) RRS feed

  • Question

  • Hi,

    We recently build and entire framework around MEF & Entity Framework. Everything is getting into place and we think about releasing this framework on Codeplex. The framework lets you create modules which contains POCOs and everything is mapped to a CMS (In House Build). It's all code-first and the table created are prefixed (schema) with the namespace of the POCO.

    Only problem is, EF does not take namespaces into account for the mappings. We can't ask every devloppers building modules to know the names of the POCOs of other existing modules (in other word : ensure unique names).

    We are already creating the mappings dynamically (with some reflection - EF could be a little bit more flexible there too by the way - we used "invoke" all over the place cause all the methods for creating mappings are generics with no "typeof" equivalent). Is there a way to make EF take the namespaces of POCOs into account? If not, it's a bummer for us.

    Thank you and keep up the good work!

    Maxime

    mseguin@absolunet.com

    http://www.absolunet.com

     

    Wednesday, September 21, 2011 5:54 PM

Answers

  • Hi W3Max,

    I hate to be the bearer of bad news but that's just the way EF works.  It finds a CLR type by a certain name and ignores the namespace.  If it finds two by the same name (in any namespace) then an exception occurs.

    I agree, it sure can cause some problems if you don't plan ahead.  And of course, you like myself, didn't plan ahead because we thought using different namespaces could be used to partition the objects, after all isn't that what namespaces are for?

    Hopefully you can work around this limitation and take it into account going forward but yeah it means you'll have to be doing some renaming and rewiring of stuff.  Hopefully a future version of  EF will address this limitation.


    Tom Overton
    • Marked as answer by Larcolais Gong Thursday, September 29, 2011 10:11 AM
    Thursday, September 22, 2011 12:13 AM

All replies

  • Hi W3Max,

    I hate to be the bearer of bad news but that's just the way EF works.  It finds a CLR type by a certain name and ignores the namespace.  If it finds two by the same name (in any namespace) then an exception occurs.

    I agree, it sure can cause some problems if you don't plan ahead.  And of course, you like myself, didn't plan ahead because we thought using different namespaces could be used to partition the objects, after all isn't that what namespaces are for?

    Hopefully you can work around this limitation and take it into account going forward but yeah it means you'll have to be doing some renaming and rewiring of stuff.  Hopefully a future version of  EF will address this limitation.


    Tom Overton
    • Marked as answer by Larcolais Gong Thursday, September 29, 2011 10:11 AM
    Thursday, September 22, 2011 12:13 AM
  • Bad choice of words. How can one plan ahead on unknown issues?
    Tuesday, November 22, 2011 1:28 PM