locked
EF code first: The EntitySet name 'TestDBContext1.Customers' could not be found RRS feed

  • Question

  • i am getting the error

    Additional information: The EntitySet name 'TestDBContext1.Customers' could not be found.

    i am trying to call sql server store procedure which return multiple result set. see my full code.

     private void button4_Click(object sender, EventArgs e)
            {
                using (var db = new TestDBContext1())
                {
                    db.Database.Initialize(force: false);
                    // Create a SQL command to execute the sproc 
                    var cmd = db.Database.Connection.CreateCommand();
                    cmd.CommandText = "[dbo].[MultiResultSet]";
    
                    try
                    {
    
                        db.Database.Connection.Open();
                        // Run the sproc  
                        var reader = cmd.ExecuteReader();
    
                        // Read Blogs from the first result set 
                        var customers = ((IObjectContextAdapter)db)
                            .ObjectContext
                            .Translate<Customer>(reader, "Customers", MergeOption.AppendOnly);
    
    
                        foreach (var item in customers)
                        {
                            Console.WriteLine(item.FirstName);
                        }
    
                        // Move to second result set and read Posts 
                        reader.NextResult();
                        var Addresses = ((IObjectContextAdapter) db)
                            .ObjectContext
                            .Translate<Addresses>(reader, "Addresses", MergeOption.AppendOnly);
    
    
                        foreach (var item in Addresses)
                        {
                            Console.WriteLine(item.Address1);
                        }
                    }
                    finally
                    {
                        db.Database.Connection.Close();
                    }
                }
    
            }

    this below lines throwing the above error message.

    var customers = ((IObjectContextAdapter)db)
    .ObjectContext
    .Translate<Customer>(reader, "Customers", MergeOption.AppendOnly);

    my db table name is Customers and Addresses. why i am getting the above error? what to change in code ?

    the interesting things is when i code like the below way then all works fine.

    var customers = ((IObjectContextAdapter)db)
    .ObjectContext
    .Translate<Customer>(reader);

    the moment i remove "Customers", MergeOption.AppendOnly from code then code works fine. just do not understand what was wrong in my above code. please some one help me to understand this. thanks

    Monday, September 26, 2016 1:08 PM

Answers

  • the issue has been solved.

    var customers = ((IObjectContextAdapter)db) .ObjectContext .Translate<Customer>(reader, "Customer", MergeOption.AppendOnly);

    this line need to be changed from

    .Translate<Customer>(reader, "Customers", MergeOption.AppendOnly);

    to

    .Translate<Customer>(reader, "Customer", MergeOption.AppendOnly);

    entity type name should be Customer instead of Customers.

    thanks

    • Marked as answer by Sudip_inn Monday, September 26, 2016 6:42 PM
    Monday, September 26, 2016 6:42 PM

All replies

  • the issue has been solved.

    var customers = ((IObjectContextAdapter)db) .ObjectContext .Translate<Customer>(reader, "Customer", MergeOption.AppendOnly);

    this line need to be changed from

    .Translate<Customer>(reader, "Customers", MergeOption.AppendOnly);

    to

    .Translate<Customer>(reader, "Customer", MergeOption.AppendOnly);

    entity type name should be Customer instead of Customers.

    thanks

    • Marked as answer by Sudip_inn Monday, September 26, 2016 6:42 PM
    Monday, September 26, 2016 6:42 PM
  • Hi Mou_inn,

    I am glad to know you solved this problem and thanks for sharing the solution. 

    It will be very beneficial for other community members who have the similar questions. 

    Best regards,

    Cole Wu



    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.

    Tuesday, September 27, 2016 8:14 AM