Entity Framework migrations: can't convert a property to a NotMapped runtime getter

.net entity-framework-6 visual-studio-2019

Question

I have this in a DAL:

public bool MyProp { get; set; }

My intention is to remove that property from the db, and calculate it at runtime instead, so I've modified it like this:

[NotMapped]
public bool MyProp => Smthng > Something.Else;

However, when I run Add-Migration -ProjectName Api.My.DAL MyClass.MyProp from the Package Manager Console, I get this error:

The property 'MyProp' is not a declared property on type 'MyClass'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.

It's asking me to ensure I'm not using NotMapped, but I want to. And even if I remove it, the error stays exactly the same. So I no longer know what to look for.

Disclaimer: I already searched on Google. Plenty of results, all for problems completely different from this one. If there is something out there, it's well hidden from me.

I'm using EF6 on VS 2019 on a .NET Framework 4.7 project.

1
0
4/17/2020 9:34:41 AM

Popular Answer

There was an additional check in a Configuration file:

Property(smwh => smwh.MyProp).IsRequired();

Removing this did the trick.

1
4/17/2020 11:01:00 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow