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

error display:

Error 3002: Problem in mapping fragments run at line 1330:Potential runtime activity of table FTPRuns’s keys (FTPRuns.ID):

Error 3002: Problem in line 1330:Potential runtime activity 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)

reason analysis:

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.

entity is the compound primary key of two attributes ftpruns. ID and ftpruns. LastRun, while the database table only has one ftpruns. ID as the primary key. All your entities must specify a composite primary key for two properties, whereas the database requires only ftPRUNs. ID to be unique.

excludes the ftpruns. LastRun attribute from the entity primary key, which may happen accidentally, or EF cannot get the primary key information from the database and must notify the entity primary key. For example, if you look at a table that has no primary key, EF will tell the entity to use all columns that are not empty as its primary key

Read More: