如何使用未映射到类的实体框架核心更新表列? [英] How do I update a table column using entity framework core that is not mapped to the class?

查看:67
本文介绍了如何使用未映射到类的实体框架核心更新表列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的对象在相应的数据库表上有一个DT_Last_Activity,当前没有映射到对象类。



它只会记录当前的日期和时间。



当我使用嵌入式SQL操作数据库时,这很好,它构成了插入或更新语句的一部分。



现在我正在使用.NET MVC Core 2.0和Entity Framework 2.0添加一个Web界面 - 因为我想学习如何使用它们。



这个列是数据库必需的,如果我找不到解决方案,我会将其添加到对象类,但我想知道是否可以使用EF Core更新它而不进行此映射,以便它可以继续保持关闭对象类。



我尝试过:



这是一个我刚刚开始研究的新问题。

解决方案

由于这一栏只会r ecord当前日期和时间,然后定义/更改它(在数据库中)以在插入时具有当前日期和时间的默认值。



SQL DEFAULT Constraint [ ^ ]



如果您需要更精细的内容,请使用存储过程或触发器。

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.

解决方案

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.


这篇关于如何使用未映射到类的实体框架核心更新表列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆