An error occurred while saving entities that do not expose foreign key properties for their relationships

后端 未结 15 1420
难免孤独
难免孤独 2020-12-08 02:43

I have a simply code in Entity Framework 4.1 code first:

PasmISOContext db = new PasmISOContext();
var user = new User();
user.CreationDate = Da         


        
15条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 02:46

    Today I faced this issue and tried the possible solutions posted above but none of them helped me. I had UnitOfWork pattern implemented and system was committing the data in last after adding all the records.

    In my case system was combining the two models and querying the DB

    Invalid object name 'dbo.RoleModelUserModel'.

    where these were two different models actually.

    I fixed this by reordering the insert statements and adding the parent entity first. In this case added the user first and issue resolved.

提交回复
热议问题