Closed sheam closed 8 years ago
Ok, now I feel stupid... but hopefully this helps someone else. I forgot to make WarehouseId and DefaultWarehouse virtual property. Chaging to the following worked:
public class User : RelationalUserAccount
{
[MaxLength(50)]
public virtual String FirstName { get; set; }
[MaxLength(50)]
public virtual String LastName { get; set; }
[ForeignKey("WarehouseId")]
public virtual Warehouse DefaultWarehouse { get; set; }
public virtual Int32 WarehouseId { get; set; }
}
Sorry for commenting on a closed issue, but I thought this might help someone else. I had the same problem so I made a unit test to ensure custom properties were virtual.
[Test]
public void AllCustomPropertiesMustBeVirtualToSupportDeletingOfChildCollectionItems()
{
var properties = typeof(MyCustomUserClass).GetProperties(BindingFlags.DeclaredOnly | .BindingFlags.Public | BindingFlags.Instance);
foreach (var accessor in properties.Select(property => property.GetAccessors().First()))
{
Assert.IsTrue(accessor.IsVirtual, string.Format("{0}.{1} was expected to be virtual but was not.", accessor.DeclaringType.Name, accessor.Name));
}
}
When I try to remove a claim from a custom user account I get this:
My user account does have a WarehouseId foreign key in it. Would this be the problem?
This is my c'tor:
I get the same error with or without those two lines of code in the c'tor.
My OnModelCreating looks like this:
My User class looks like this:
I am on EF 6, .net 4.5.
Am I not allower to have Nav properties in my user account?