how to handle a pattern i use that other may also want to use #745
Replies: 2 comments 3 replies
-
one thing i was thinking of to possibly support this might be an attribute that could be applied to the entity models. so that when for example the action is http patch or http put to update a record each item with that attribute would in effect remove the fields from the incoming patch data and the OData OnUpdating interceptor allows the server to provide updated data for the fields. the idea is that i do not want the client to ever directly set the data in the 4 columns i use to keep track of record creation and update. the attribute could specify which methods to do this on (ODataPost, ODataPatch,ODataDelete) so its up to the author which ones to manage this way and for what actions. having something like this integrated with Restier could help make building standard logic that much easier i think. |
Beta Was this translation helpful? Give feedback.
-
None of that is necessary, what you are asking for is what Restier was specifically designed for. You just need to use the The legacy documentation we have here still (somewhat) applies: https://restier.readthedocs.io/en/latest/server/interceptors/. Here's a rough example: public virtual async Task OnInsertingYourEntityAsync(YourEntity entity)
{
ArgumentNullException.ThrowIfNull(entity, nameof(entity));
entity.CreatedById = ClaimsPrincipal.Current.GetIdClaim();
entity.DateCreated = DateTime.UtcNow;
await Task.CompletedTask;
} |
Beta Was this translation helpful? Give feedback.
-
so i am making good progress overall.... and now i am thinking about what way might be the best way to handle this:
in all of my database tables i normally define a few standard columns that i want to handle in a standard manner. some of this might be done by extending entity framework but some this might be better to build into how OData works i think...
son in the table i will have two datetime offset columns 'Date Created', 'Last Changed' and two nvarchar columns 'Who Created', 'Who Changed'
when any get happens they should go out as part of the data ....
when a record is going to be posted / created i do not want the client to supply any of that data, i want OData and or Entity Framework to take care of that much like an identify / auto number ....
on update i do not want the client to supply that data and i want the server side OData and or Entity Framework to fill in the Change date and Who Changed.
now the "Who: i think has to be in the web api - i do not think that EF will have the http info on who the user is.
the dates i can see pssible ways to do them in ef.
but i want to see if anyone has any great ideas or related ways they do this.
Beta Was this translation helpful? Give feedback.
All reactions