Reputation: 4430
I write application using Entity Framework, I write any code in "ButtonSave" like thís:
_objEntities = new PCApp_TaxitechEntities();
contact objModel = new contact();
objModel.Name = customerName;
objModel.Phone = PhoneNumber;
_objEntities.contacts.Add(objModel);
int Result = _objEntities.SaveChanges();
This throws exception in line:
int Result = _objEntities.SaveChanges();
With message like:
An error occurred while updating the entries: {"Invalid object name 'dbo.contact'."}
Here my connectionString:
<connectionStrings>
<add name="PCApp_TaxitechEntities"
connectionString="Data Source=.\sqlexpress;Initial Catalog=PCApp_Taxitech;
User ID=sa;Password="/>
</connectionStrings>
Of courses, In SQL Server, I have database PCApp_Taxitech
.
I don't know when call SaveChanges()
method this application throw exception.
Upvotes: 0
Views: 4273
Reputation: 28272
The problem is that somehow your database table is called contacts
(plural), while Entity Framework is trying to write to a table called contact
(singular).
The easy solution would be to just rename the table, but if you have generated your database from your EDMX, it'd be wise to revise it and see where it may have pluralized the database table name, but not the mapped table name (which sounds pretty weird).
Upvotes: 1