You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have multiple resources where attributes and relations are required (set through the fluent API in the EF Core context).
Although I set the values of those attributes and relations, in my custom (overridden) controller method, it seems like JADNC ignores those values on creation.
publicclassExample:Identifiable<Guid>{// RequiredpublicstringUserId{get;set;}publicUserUser{get;set;}// Set through the json api[Attr(Capabilities=AttrCapabilities.AllowCreate|AttrCapabilities.AllowView|AttrCapabilities.AllowSort|AttrCapabilities.AllowFilter)]publicstringQuery{get;set;}// Required[Attr]publicstringValue{get;set;}// Set automatically on create and update (trigger)[Attr]publicDateTimeUpdated{get;set;}// Set automatically on create (trigger)[Attr]publicDateTimeCreated{get;set;}}
The example definitely helps for required relationships and attributes but the question of where I should place the business logic emerges.
Only the attributes which are marked with the Create capability get copied over from resourceFromRequest to resourceForDatabase, in the {resource}Repository. This is understandable when you solely rely on the input from the request, but in my case, most of the attributes will be set based on business logic (dependent on one of the attributes in the request payload).
The Create capability is only used for request body validation and plays no role in copying. If you have properties whose value directly depends on other resource properties, I would make them calculated properties instead. But if they depend on injected services, you'll need to do something similar to what's described here (override CreateAsync).
We intend to make all this easier with #934 (suggestions welcome).
DESCRIPTION
I have multiple resources where attributes and relations are required (set through the fluent API in the EF Core context).
Although I set the values of those attributes and relations, in my custom (overridden) controller method, it seems like JADNC ignores those values on creation.
What is the recommended approach?
STEPS TO REPRODUCE
JsonApi service:
Example resource
Example controller
EXPECTED BEHAVIOR
I expect the resource to be created with the assigned values.
ACTUAL BEHAVIOR
Violation of not-null constraints for resources with required attributes and relations (DbUpdateException).
VERSIONS USED
The text was updated successfully, but these errors were encountered: