Every time I try to save something into the database I get the error:
A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'PackageId'.
Following is the code that does this, the line DB.SaveChanges();
.
public ActionResult CreatePackage(Package package, string MaterialId, string SubCategoryId, string Companies)
{
ModelState.Clear();
//add stuff to package
package.CreatedDate = DateTime.Now;
DB.Packages.Add(package);
DB.SaveChanges();
return Redirect(Url.Action("Index", "Material") + "#Packages");
}
Below is the diagram of the table that throws the exception:
After doing some heavy reasearch I on stackoverflow I believe that there might be something wrong with my foreign keys:
- A dependent property in a ReferentialConstraint is mapped to a store-generated column
- A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'ID'
- A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'FeeID'
However I can't see to find what can possibl be wrong with my code, nor my DB. I am trying to create a many-to-many relationship between the table Packages and COmpany. A Company can be in several packages, and a packes can be used by several companies.
What I find odd, is that this only happens when I try to create a new object. For example, If I have a Package with PackageId = 0
and a Company with CompanyId = 0
and if I run the SQL server statement:
INSERT INTO GATE_Package_Company
VALUES (0, 0);
Everything works fine because the previous object already exist. But if I try to create a new Pacakge object (one that does not exist yet) and I try to save it, I get the error. Right now it is simply not possible to add new packages :S
What am I missing?