开发者

Assigning FK when creating a model results in "A dependent property in a ReferentialConstraint is mapped to a store-generated column."

I have this code and the following EF model:

Assigning FK when creating a model results in "A dependent property in a ReferentialConstraint is mapped to a store-generated column."

 var modelToAdd = new Package
                {
                    PackageID = model.LearningPackageID,   // not auto-generated PK!
                    Name = model.Name,
                    Description = model.Description,
                    DateCreated = DateTime.Now,
                    ModuleID = model.ModuleID
                };
                activityRepo.AddPackage(modelToAdd);

This doesn't work too

var modelToAdd = new Pacakge
            {
                PackageID = model.LearningPackageID,  // not auto-generated PK!
                Name = model.Name,
                Description = model.Description,
                DateCreated = DateTime.Now


            };
// assume moduleID is defined to a valid module ID (yes, tested)
var module = entities.Modules.Where( x => x.ID == moduleID);
module.Pacakges.Add(modelToAdd);
entities.SaveChanges();

Basically, there's a 1:M relationship beteen Modules and Packages. However, when I try to set ModuleID (which is gotten from a dropdown), for both 开发者_如何学编程cases I'll get:

A dependent property in a ReferentialConstraint is mapped to a store-generated column.

PackageID is alpha-numeric and is not auto-generated, either is ModuleID, as it is a FK

What should I do?


Please check that the Package.ModuleID conceptual property and store column (I suppose you are using a Devart Entity model, so you can check it in Model Explorer->Model.Store) have StoreGeneratedPattern set to None. The non-Entity Key referential constraint property can be neither Identity nor Computed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜