合并代码第一和数据库首先在单一模型? [英] Combine Code First & Database First In Single Model?

查看:91
本文介绍了合并代码第一和数据库首先在单一模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在同一上下文中结合首例和数据库优先编辑EDMX文件时,我们遇到了大量的开发时间性能问题(需要1.5分钟的时间才能保存)。我已将我们的非插入/更新/删除UDF /存储过程移动到自动生成模型第一个代码的自定义T4模板,但是我似乎无法获得 OnModelCreating 在EDMX涉及时被调用。

Is there a way to combine code-first and database-first in the same context? We are running into massive development-time performance problems when editing the EDMX file (it takes 1.5 minutes to save). I've moved our non-insert/update/delete UDFs/stored procs to some custom T4 templates that automatically generate model-first code, but I can't seem to get OnModelCreating to be called when EDMX is involved.

我们考虑过的其他事情,但不会因某种原因而工作:

Other things we've considered, but won't work for one reason or another:


  1. 我们不能(合理地)将代码分离到多个上下文,因为我们的实体关系有很多重叠。

  1. We can't (reasonably) separate our code to multiple contexts as there is a lot of overlap in our entity relationships. It also seems like quite a people who have gone this route regret it.

我们尝试了两种不同的上下文,但实体和amp之间有很多连接; UDF的。这可能是我们最后的希望,但我真的很想避免。

We tried having 2 different contexts, but there are quite a few joins between Entities & UDFs. This may be our last hope, but I'd REALLY like to avoid it.

我们不能切换到Dapper,因为我们不幸的是大量使用 IQueryable

We can't switch to Dapper since we have unfortunately made heavy use of IQueryable.

我们试图完全执行Code-First,但是我们有在EDMX中使用不支持(主要涉及插入/更新/删除存储过程映射)。

We tried to go completely to Code-First, but there are features that we are using in EDMX that aren't supported (mostly related to insert/update/delete stored procedure mapping).


推荐答案

感谢大家的深思熟虑的答案。

Thank you to everyone for the well thought out and thorough answers.

其他许多答案都假定EF中的存储过程映射代码 - 第一个工作是一样的,但他们没有。我有点模糊,因为从我看过它已经6个月了,但我相信EF 6.3代码第一个存储过程要求你把你的实体的每一列传递到你的插入/更新存储过程,而你只将密钥列传递给您的删除过程。没有选择选择可以通过哪些列。我们有一个要求来维护谁删除了一个记录,所以我们必须传递一些额外的信息,除了一个简单的关键。

Many of these other answers assume that the stored procedure mappings in EF Code-First work the same, but they do not. I'm a bit fuzzy on this as it's been about 6 months since I looked at it, but I believe as of EF 6.3 code first stored procedures require that you pass every column from your entity to your insert/update stored procedure and that you only pass the key column(s) to your delete procedure. There isn't an option to pick and choose which columns you can pass. We have a requirement to maintain who deleted a record so we have to pass some additional information besides just a simple key.

就是说,我最后做的是使用一个T4模板,从数据库自动生成我的EDMX /上下文/模型文件(带有一些额外的元数据)。这使得我们的开发人员的时间从1.5分钟降到了大约5秒。

That being said, what I ended up doing was using a T4 template to automatically generate my EDMX/Context/Model files from the database (with some additional meta-data). This took our developer time experience down from 1.5 minutes to about 5 seconds.

我希望EF存储过程的映射将被改进,以实现模仿EDMX,然后我可以代码生成Code-First映射,并完全删除EDMX代码。

My hope is EF stored procedure mappings will be improved to achieve parody with EDMX and I can then just code-generate the Code-First mappings and remove the EDMX generation completely.

这篇关于合并代码第一和数据库首先在单一模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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