Entity Framework 6 Code First Trigger(实体框架 6 代码优先触发器)
问题描述
我正在使用 Entity Framework 6 Code First,并希望创建一个触发器.
我该怎么做?
我需要触发器的原因是因为用户可以直接编辑数据库,也可以通过我正在编写的程序编辑数据库,并且我需要确保表中的 2 列不都是空的,也不都是空的.
我一直在寻找,但找不到路.
有没有办法先用代码指定触发器?
Entity Framework 不支持触发器,虽然你当然可以手动执行会创建触发器的语句,但是你需要在表格被创建(如果使用迁移).
您可以使用 Ladislav 在 EF 4.1 代码优先向表中添加触发器
请注意他的警告,但是,EF 不会知道触发器中所做的任何更改.如果您的意图只是确保表中的 2 列不为空,则最好使用约束(EF 也不支持约束,但您可以手动添加它们).
I'm using Entity Framework 6 Code First, and would like to create a Trigger.
How do I do this?
The reason I need the trigger is because a user may either edit the database directly or through a program I'm writing, and I need to make sure 2 columns in a table are not both null, and are not both not null.
I've been looking and can't find a way.
Is there any way to specify a trigger using code first?
Entity Framework has no support for triggers, although you can certainly manually execute a statement that would create a trigger, but you would need to do this after the table was created (if using migrations).
You can use the technique specified by Ladislav in EF 4.1 code-first adding a trigger to a table
Take note of his warning, however, EF will not be aware of any changes made in the trigger. If your intent is merely to ensure that 2 columns in a table are not null, you'd be better served with a constraint (constraints are also not supported by EF, but you can add them manually).
这篇关于实体框架 6 代码优先触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架 6 代码优先触发器
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01