Click here to Skip to main content
15,878,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My objects have a DT_Last_Activity on their corresponding database tables that is not currently mapped to the object classes.

It will only ever record the current date and time.

This was fine when I was manipulating the database using embedded SQL where it formed part of the Insert or Update statement.

Now I am adding a web interface using .NET MVC Core 2.0 and Entity Framework 2.0 - because I want to learn how to use them.

This column is mandatory on the database and if I cannot find a solution I will add it to the object classes but I would like to know if it is possible to update it using EF Core without making this mapping so that it can continue to remain off the object class.

What I have tried:

This is a new problem that I am only beginning to look into.
Updated 24-Aug-18 6:43am

1 solution

Since this column "will only record the current date and time", then define / alter it (in the database) to have a default value of the "current date and time" on insert.

SQL DEFAULT Constraint[^]

If you need something more elaborate, use a stored procedure or trigger.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900