-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicitly set constructor binding should stop convention from running #13891
Comments
This is currently by-design per: #10852, but also see #10865. The constructor binding can be set explicitly using internal code.
modelBuilder.Entity<Project>(e =>
{
var nameProperty = e.Property(p => p.Name).Metadata;
var anotherProperty = e.Property(p => p.AnotherProp).Metadata;
var lastNameProperty = e.Property(p => p.Lastname).Metadata;
e.Metadata[CoreAnnotationNames.ConstructorBinding]
= new DirectConstructorBinding(
typeof(Project).GetConstructor(new [] { typeof(string), typeof(string), typeof(int) }),
new []
{
new PropertyParameterBinding(nameProperty),
new PropertyParameterBinding(lastNameProperty),
new PropertyParameterBinding(anotherProperty),
});
}); However, I found while working on this that the convention still runs and throws even though its result would not be used--this is a bug. I was able to workaround this by adding a private parameterless constrctor to the entity type: public class Project
{
private Project()
{
}
...
} This allows the convention to succeed, with the result being that the explicitly configured constructor is used. |
Hi All |
@ahedreville Currently planned for the 3.0 release; that's why the issue is in the "3.0.0" milestone. |
EF Core version: 2.2.0-rtm-35637
The text was updated successfully, but these errors were encountered: