Brumla
Brumla
CC#
Created by surwren on 12/18/2024 in #help
My constructor sets the attribute, so why is EFcore complaining?
it solves the problem when the required is used, I don`t take care about the background why this is set in this way in EF entity.
47 replies
CC#
Created by surwren on 12/18/2024 in #help
My constructor sets the attribute, so why is EFcore complaining?
47 replies
CC#
Created by surwren on 12/18/2024 in #help
My constructor sets the attribute, so why is EFcore complaining?
no, this is the part in those {} brackets: var somevar = new MyClass(... here goes constructor args...) { someProperty = someInitialValueForRequiredProperty, otherProperty = otherValue}
47 replies
CC#
Created by surwren on 12/18/2024 in #help
My constructor sets the attribute, so why is EFcore complaining?
in fact, the complains go from the C# itself as you have to use object initializer to initialize the properties here.
47 replies
CC#
Created by surwren on 12/18/2024 in #help
My constructor sets the attribute, so why is EFcore complaining?
of course, you can initialize all the properties in the same way like the UpMedia property
47 replies
CC#
Created by surwren on 12/18/2024 in #help
My constructor sets the attribute, so why is EFcore complaining?
please try it like this:
var media = new UpMedia("myOtherValue") {
OwnerId = Guid.NewGuid()
};

class UpMedia {
public required Guid OwnerId {get;set;}
public string SomeOtherValue {get;set;}

public UpMedia(string someOtherValue) {
SomeOtherValue = someOtherValue;
}
}
var media = new UpMedia("myOtherValue") {
OwnerId = Guid.NewGuid()
};

class UpMedia {
public required Guid OwnerId {get;set;}
public string SomeOtherValue {get;set;}

public UpMedia(string someOtherValue) {
SomeOtherValue = someOtherValue;
}
}
47 replies