none
Entity FrameWork Database first RRS feed

  • Question

  • Hello

    I'm working on entity Framework data base first,  in my model's properties when I set code generation strategy to "none" , in my class diagram my entity class  inherited "Db Context" but another classes didn't inherit "Entity object".

    when I set code generation strategy to "Default",in my class diagram my entity class  inherited both "Db Context" and "object context" !!  another classes  inherit "Entity object", and because of a class can't inherited two class it errors me when I'm instantiating my entity class in my commands.

    what can I do ,that in my class diagram my entity class inherits db context and another class inherit entity object? 

    Thanks for your help

    Tuesday, August 27, 2013 2:40 PM

Answers

  • First decide which context you are going to use and set the Code Generation Strategy property accordingly, Default = ObjectContext and None = DbContext. 

    If using ObjectContext then in Solution Explorer delete the two nodes that end in .tt, these are the auto generated code for the DbContext.

    If you are using the DbContext then in Solution Explorer delete all the auto generated class under the node xxx.Designer.cs which are used for ObjectContext.

    Once you have done the above compile the application and you should be good.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 27, 2013 3:36 PM
  • Hi Bkshn,

    Here are some differences between ObjectContext and DbContext for your information.

    Both generators produce the same entities, however, ADO.NET POCO Entity Generator is based on ObjectContext's API, whereas ADO.NET DbContext Generator is based on DbContext's API.

    DbContext's API has a few very nice new features (Local, Query on navigation property, etc.) and API is somehow simplified but at the same time it looks like some features used in ObjectContext API are missing in DbContext API (or at least it has not been explored enough yet).

    ObjectContext API or DbContext API? ObjectContext API is much better covered by documentation and blog posts. You can find plenty of examples about it. Also its limitations are already well known. DbContext API is new release. A very promising release, mostly because of the code-first approach. There is still a very limited number of blog posts, no book and the API is not proven enough. So it depends if you are ready to fight with new API? If not, then ObjectContext API is still a good choice because you don't need the code-first approach.

    Best Regards,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, August 28, 2013 7:53 AM
    Moderator
  • I guess I really don't understand what you're asking for. The top image is showing Entity Framework using DbContext the bottom image is showing Entity Framework using ObjectContext.

    To your statement, "when I set code generation strategy = none , I have DbContext for my Entities class, but I don't have Entity Object for another class", that is correct when using DbContext the classes get added to a collection called DbSet<className>.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by bkshn Wednesday, September 4, 2013 2:27 AM
    Tuesday, September 3, 2013 11:58 PM

All replies

  • First decide which context you are going to use and set the Code Generation Strategy property accordingly, Default = ObjectContext and None = DbContext. 

    If using ObjectContext then in Solution Explorer delete the two nodes that end in .tt, these are the auto generated code for the DbContext.

    If you are using the DbContext then in Solution Explorer delete all the auto generated class under the node xxx.Designer.cs which are used for ObjectContext.

    Once you have done the above compile the application and you should be good.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 27, 2013 3:36 PM
  • Hi Bkshn,

    Here are some differences between ObjectContext and DbContext for your information.

    Both generators produce the same entities, however, ADO.NET POCO Entity Generator is based on ObjectContext's API, whereas ADO.NET DbContext Generator is based on DbContext's API.

    DbContext's API has a few very nice new features (Local, Query on navigation property, etc.) and API is somehow simplified but at the same time it looks like some features used in ObjectContext API are missing in DbContext API (or at least it has not been explored enough yet).

    ObjectContext API or DbContext API? ObjectContext API is much better covered by documentation and blog posts. You can find plenty of examples about it. Also its limitations are already well known. DbContext API is new release. A very promising release, mostly because of the code-first approach. There is still a very limited number of blog posts, no book and the API is not proven enough. So it depends if you are ready to fight with new API? If not, then ObjectContext API is still a good choice because you don't need the code-first approach.

    Best Regards,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, August 28, 2013 7:53 AM
    Moderator
  • Hello  Fernando Soto

    Thanks for your answer.

    when I set code generation strategy = none , I have DbContext for my Entities class, but I don't have Entity Object for another class.

    I show my problem in two pictures. I have button pic .


    PIC1

    but I want this pic that another class  inheritance Entity Object. 

    PIC

    I'll appreciate your help.


    • Edited by bkshn Tuesday, September 3, 2013 3:16 PM
    Tuesday, September 3, 2013 3:13 PM
  • I guess I really don't understand what you're asking for. The top image is showing Entity Framework using DbContext the bottom image is showing Entity Framework using ObjectContext.

    To your statement, "when I set code generation strategy = none , I have DbContext for my Entities class, but I don't have Entity Object for another class", that is correct when using DbContext the classes get added to a collection called DbSet<className>.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by bkshn Wednesday, September 4, 2013 2:27 AM
    Tuesday, September 3, 2013 11:58 PM