Best practices: Where should I assign value to an EF model DateTime property
Hello,
I would need to assign
DateTime.UtcNow
to a property called CreatedAt
.
Should this be done in the model, business logic layer or repository layer?
6 Replies
It should just be autogenerated on add
By the database
dont have to tell it to auto gen?
iirc the default is only for props named Id or ClassNameId
ye
oh i misunderstood what you said nevermind
.HasDefaultValueSql("getdate()")
Or whatever the function for getting the date is in the database you useOh, I haven't thought of that at all.... Yes that's how it should be done
Thank you