none
EDMX canvas and generating a database from Model question RRS feed

  • Question

  • I generated the database from the model now I notice that all the tables have an "s" appended to then Userid object translated to Userids in SQL.

    which when I run the code

    Userid userid = db.Userids.Find(id);

    gives me this error: System.InvalidOperationException: 'The entity type Userid is not part of the model for the current context.'

    is the "s" added at the end of all the tables correct?

    THE ACTUALL ERROR I GET

    System.InvalidOperationException
      HResult=0x80131509
      Message=The entity type Userid is not part of the model for the current context.
      Source=<Cannot evaluate the exception source>
      StackTrace:
    <Cannot evaluate the exception stack trace>

    • Edited by robMerritt Friday, July 3, 2020 8:38 PM UPDATE
    Friday, July 3, 2020 7:51 PM

All replies

  • Hi robMerritt,
    Based on your error, I have some suggestions you can refer to.
    1.In case you are employing the connection string produced at the time including the EDMX file in :base(“EDMXConnString”), you will probably have this problem.
    You can try to solve  this by making a standard connection string as follows:

    <add name="MyConnString" connectionString="Data Source=server; Initial Catalog=db_name; User ID=user_id; Password=password; Connect Timeout=60;" providerName="System.Data.SqlClient" />

    2. You can override the OnModelCreating method and put the following code in your custom DbContext class:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Estate>().ToTable("Estate");
    }

    3. EF will search for a connection string with the same name as the context's class name  by default, you can try to change the connection string name to context's class name.
    Here are also some similar threads you can refer to.
    Hope these are helpful to you.
    [The entity type <type> is not part of the model for the current context]
    [Getting “The entity type <model> is not part of the model for the current context.”]
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 6, 2020 2:04 AM