I have the following classes with CODE FIRST:
public class License
{
public License()
{
Assignments = new List<FeatureAssignment>();
}
public virtual List<FeatureAssignment> Assignments { get; set; }
public bool CanExpire { get; set; }
public int LicenseId { get; set; }
public int ProductId { get; set;}
public virtual Product Product { get; set; }
}
and
public class FeatureAssignment
{
public int FeatureAssignmentId { get; set; }
public virtual License License { get; set; }
public int LicenseId { get; set; }
public virtual LicenseFeature LicenseFeature { get; set; }
public int LicenseFeatureId { get; set; }
}
with
public class LicenseFeature
{
public int LicenseFeatureId { get; set; }
[Column(TypeName = "VARCHAR")]
[StringLength(450)]
[Index(IsUnique = true)]
public string FeatureName { get; set; }
public string Description { get; set; }
public int ProductId { get; set;}
public virtual Product Product { get; set;}
}
last but not least
public class Product
{
public int ProductId { get;set;}
public string ProductName { get;set;}
public virtual ICollection<License> Licenses { get; set; }
public virtual ICollection<LicenseFeature> LicenseFeatures { get; set; }
}
So the intention is to provide licenses for a dedicate product. Every license can have multiple feature assignment and a product can have multiple licenses.
Now when the DB is created I get the following error:
System.Data.SqlClient.SqlException: 'Introducing FOREIGN KEY constraint 'FK_dbo.LicenseFeatures_dbo.Products_ProductId' on table 'LicenseFeatures' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Perhaps I miss the forrest for the trees, but I thought it should be possible to have feature assignement for a dedicated license? Did I miss an attribute for the foreign keys?
*********** UPDATE **********
I provided all affected classes. In the first posting the product class was missing - sorry for that :-(