The property X is of type Y which is not supported by current database provider
It seems it was a fairly simple answer in the end, the error had me looking at the structure of my classes and trying to work out what had gone wrong. The problem was that in my BranchContext
(which I did not consider sharing in my question), I hooked into OnModelCreating
and set Address as required
Wrong
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EmployeeBranch>()
.HasKey(s => new { s.BranchId, s.EmployeeId });
modelBuilder.Entity<Branch>()
.Property(s => s.Address).IsRequired();
modelBuilder.Entity<Branch>()
.Property(s => s.Name).IsRequired();
base.OnModelCreating(modelBuilder);
}
Right
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EmployeeBranch>()
.HasKey(s => new { s.BranchId, s.EmployeeId });
modelBuilder.Entity<Address>()
.Property(s => s.AddressLine1).IsRequired();
modelBuilder.Entity<Address>()
.Property(s => s.Postcode1).IsRequired();
modelBuilder.Entity<Address>()
.Property(s => s.Postcode2).IsRequired();
...the other required elements...
modelBuilder.Entity<Branch>()
.Property(s => s.Name).IsRequired();
base.OnModelCreating(modelBuilder);
}
Assumption: the goal is to make Address
a required property of Branch
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Branch>()
.HasOne(s => s.Address)
.WithMany()
.IsRequired();
}
You can use the Fluent API to configure whether the relationship is required or optional
Source: Required and Optional Relationships
This error might also pop up in silly situations of referencing a navigation property instead of a mapped property within a constraint or similar:
modelBuilder.Entity<TheEntity>().HasKey(ma => new { ma.SomeKey, ma.NavPropInsteadOfProp });
Unfortunately, the error is not explicit enough, but temporarily commenting out the culprit from the error will lead to the source.