1. 程式人生 > >Error 3002: Problem in mapping fragments | c# linq to entities

Error 3002: Problem in mapping fragments | c# linq to entities

錯誤展示:

Error 3002: Problem in mapping fragments starting at line 1330:Potential runtime violation of table FTPRuns’s keys (FTPRuns.ID): Columns (FTPRuns.ID) are mapped to EntitySet FTPRuns’s properties (FTPRuns.ID) on the conceptual side but they do not form the EntitySet’s key properties (FTPRuns.ID, FTPRuns.LastRun).

原因分析:

Your entity model has the combination of the two properties FTPRuns.ID and FTPRuns.LastRun as entity key while your table has only the column FTPRuns.ID as primary key. So in your model you specify that the combination of FTPRuns.ID and FTPRuns.LastRun must be unique while your database has the stronger requirement that FTPRuns.ID alone must be unique.

Just exclude the property FTPRuns.LastRun from the entity key. Maybe this happened accidentally or the Entity Framework could not get primary key information from the database and had to infer the entity key. For example views have no primary key and the Entity Framework will infer the entity key as the combination of all non-nullable columns.

實體是兩個屬性FTPRuns.ID和FTPRuns.LastRun的複合主鍵,而資料庫表僅僅只有一個FTPRuns.ID作為主鍵。所有你的實體指定兩個屬性的複合主鍵必須唯一,而資料庫則要求僅僅FTPRuns.ID必須唯一。

從實體主鍵中排除FTPRuns.LastRun屬性,這個可能是偶然發生的,或者EF不能從資料庫得到主鍵資訊,並且必須通知實體主鍵。例如,看那些沒有主鍵的表,EF將通知實體以所有不為空的列作為實體主鍵