none
Can an Entity Model (.edmx file) inherit from DataContext instead of DbContext? RRS feed

  • Question

  • I can run an xml.linq query against the Northwind Customers table using a DataContext in a test project.  But in another test project I added an .edmx file (ADO.Net Entity Model) which uses a DbContext (on the same Northwind DB Customers table) which does not support my xml.linq query.  The xml.linq query seems to be looking for

    this.GetTable<Customer>;

     I'm trying to modify the Entity Model class to inherit from DataContext instead of DbContext to run the xml.linq query.  If not possible to use a DataContext with an Entity Model would it be possible to modify the Entity Model Class with DbContext to do a similar thing?  What modifications could I make so this can work? 

    (I changed public partial class NorthwindEntities : DbContext to

    public partial class NorthwindEntities : DataContext)

    Thanks


    Rich P





    • Edited by Rich P123 Thursday, November 21, 2013 7:42 PM ....
    Thursday, November 21, 2013 7:33 PM

Answers

  • Hello,

    In my opinion, it is impossible. The DataContext is used for Linq2Sql and the DbContext is used for entity framework, they are completely different object.

    For changing public partial class NorthwindEntities : DbContext to public partial class NorthwindEntities : DataContext), why not create the .dbml item directly since it has already been provided.

    Or we can convert the .dbml item to .edmx item, for this, please have a look at the link below:

    http://blogs.msdn.com/b/efdesign/archive/2009/08/13/linq-to-sql-to-entity-framework-conversion-template.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 25, 2013 1:19 AM
    Moderator