Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateCreated or Modified Column - Entity Framework or using triggers on SQL Server

After I read one question in attached link, I got a sense of how to set DateCreated and DateModified columns in Entity Framework and use it in my application. In the old SQL way though, the trigger way is more popular because is more secure from DBA point of view.

So any advice on which way is the best practice? should it be set in entity framework for the purpose of application integrity? or should use trigger as it make more sense from data security point of view? Or is there a way to compose trigger in entity framework? Thanks.

EF CodeFirst: Rails-style created and modified columns

BTW, even though it doesn't matter much, I am building this app using ASP.NET MVC C#.

like image 364
anIBMer Avatar asked May 15 '13 00:05

anIBMer


People also ask

Does Entity Framework support triggers?

Triggers. Add triggers to your entities with insert, update, and delete events. There are three events for each: before, after, and upon failure.

Can insert or update be performed on complex views using triggers?

Yes ,you can insert,update,delete using trigger. view is nothing but a table. Like creating another table to the main table.

What are triggers and views?

Identifier. You can use the trigger action to update the tables underlying the view, in some cases updating an otherwise “non-updatable” view. You can also use INSTEAD OF triggers to substitute other actions when INSERT, DELETE, or UPDATE statements reference specific columns within the database.

What is EF in SQL?

Entity Framework Core is a modern object-database mapper for . NET. It supports LINQ queries, change tracking, updates, and schema migrations. EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.


1 Answers

Entity Framework 6 has interceptors which can be used to set created and modified. I wrote an article how to do it: http://marisks.net/2016/02/27/entity-framework-soft-delete-and-automatic-created-modified-dates/

like image 63
marisks Avatar answered Sep 18 '22 17:09

marisks