问题描述
可以在EF6 Code First中调用TVF吗?
Is it possible to call a TVF in EF6 Code First?
我首先使用EF6数据库开始一个新项目,而EF可以将TVF导入到模型中,并将其称之为罚款。
I started a new project using EF6 Database first and EF was able to import a TVF into the model and call it just fine.
但是,更新模型变得非常耗时且大型只读数据库出现问题,没有我遇到的RI。
But updating the model became very time consuming and problematic with the large read-only db with no RI that I'm stuck dealing with.
所以我试图首先使用Power Tools逆向工程工具转换为EF6代码来生成上下文和模型类。
So I tried to convert to EF6 code first using the Power Tools Reverse Engineering tool to generate a context and model classes.
不幸的是,逆向工程工具没有导入TVF。
Unfortunately the Reverse Engineering tool didn't import the TVFs.
接下来,我尝试将DBFunctions从我的旧数据库第一个DbContext复制到新的Code First DbContext,但这给了我一个错误,我的TVF:
无法解析为有效的类型或功能。
Next I tried to copy the DBFunctions from my old Database First DbContext to the new Code First DbContext, but that gave me an error that my TVF: "cannot be resolved into a valid type or function".
是否可以为TVF创建一个代码Fluent映射?
Is it possible to create a code first Fluent mapping for TVFs?
如果没有,是否有工作
我想我可以使用SP而不是TVF,但是希望我可以使用大多数TVF来处理我遇到的有问题的数据库。
I guess I could use SPs instead of TVFs, but was hoping I could use mostly TVFs to deal with the problematic DB I'm stuck with.
感谢任何解决方法
推荐答案
可能。我创建了一个自定义模型约定,允许在EF6.1中的CodeFirst中使用存储功能。该公约可在NuGet 上获得。以下是包含所有详细信息的博客的链接:
This is now possible. I created a custom model convention which allows using store functions in CodeFirst in EF6.1. The convention is available on NuGet http://www.nuget.org/packages/EntityFramework.CodeFirstStoreFunctions. Here is the link to the blogpost containing all the details: http://blog.3d-logic.com/2014/04/09/support-for-store-functions-tvfs-and-stored-procs-in-entity-framework-6-1/
这篇关于首先支持EF6代码中的表值函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!