最佳实践 - 混合表实体与视图的EntityFramework实体?

问题描述:

我有我想与实体框架交互的遗留数据库。

I have a legacy database that I'd like to interact with Entity Framework.

该数据库用于存储有关信息飞行高度规范化。为了更容易地与一些数据进行操作,多个SQL视图的已被写入变平数据和枢转某些多表连接到多个逻辑信息

The database is highly normalised for storing information about flights. In order to make it easier to work with some of the data, a number of SQL Views have been written to flatten data and to pivot certain multi-table joins into more logical information.

后迅速找了这一点,我看到在EF使用浏览两个问题。

After quickly looking over this I see two problems with using Views in EF.


  1. 该视图包含了很多很多的按键。一些快速谷歌搜索似乎表明我需要手动编辑EDMX文件删除此信息。

  1. The Views contains lots and lots of Keys. Some quick googling seems to indicate I will need to manually edit the EDMX file to remove this info.

的观点并不具有对其他表实体的任何关系。这些协会需要以手动添加到链接查看 - >表

The Views don't have any relationships to the other table entities. These associations need to be manually added in order to link a View -> Table.

这两个看起来像大当谈到刷新从数据库中,当德DBA团队进行修改模型的痛点。

Both of these seem like major pain points when it comes to refreshing the Model from the DB, when teh DBA team make changes.

这只是你工作时需要忍受的东西EF还是有什么建议的模式/实践来处理这些。

Is this just something you need to "put up with" when working with EF or are there any suggested patterns/practices to deal with these.

混合表,实体查看实体是确定的,在很大程度上取决于你的需求。

我的经验是这些东西,你将不得不去处理。

My experience has been these are things you are going to have to deal with.

当我使用实体第一次开始,我用的观点很多,因为我被告知,我需要使用它们。因为我变得更熟悉的实体,我开始的喜欢的使用表实体在视图实体;主要是因为我觉得我有更多的控制。视图是当您呈现只读信息确定,或像你描述(flattend数据,枢轴,连接等);但是,当您的需求变化,你现在必须添加CRUD,你将不得不使用存储过程或更改模型无论如何使用表entites的,所以你还不如用表的实体从一开始。

When I first started using Entity, I used views a lot because I was told I needed to use them. As I became more familiar with Entity I began to prefer the use of table-entities over view-entities; mainly because I felt I had more control. Views are ok when you are presenting read-only info, or as you described (flattend data, pivots, joins etc.); however, when your requirements change and you now have to add CRUD, you are going to have to use stored procedures or change your model to use table-entites anyway, so you might as well use table-entities from the start.

该视图包含了很多很多的钥匙。一些快速谷歌搜索似乎
表示我将需要手动编辑EDMX文件删除此
信息。

The Views contains lots and lots of Keys. Some quick googling seems to indicate I will need to manually edit the EDMX file to remove this info.

这是不是真的永远为我一个问题。您可以撤消在设计视图实体的按键。如果你谈论的存储层这样的观点,那么,你可以,使其工作,但只要你从数据库更新模式,你将不得不重新做到这一点 - 我不建议这样做。你最好与你的DBA来调整数据库中的关键制约因素的工作。

This wasn't ever really a problem for me. You can undo keys of the view-entity in the designer. If your talking about doing this for the view in the storage layer, then yes, you can, to make it work, but as soon as you update your model from the database, you are going to have to do this over again -- I wouldn't recommend doing this. You are better off working with your DBA to adjust the key constraints in the database.

该视图没有其他任何关系表实体。
这些协会必须以链接查看
手动添加 - >表

The Views don't have any relationships to the other table entities. These associations need to be manually added in order to link a View -> Table.

这是往往​​m>的我的一个问题。有时你可以添加键和没有任何问题建立关系,但很多时候,您可能需要更改密钥和/或关系DB使它工作 - 这取决于你的要求;你可能要应对这种通过表实体时也是如此。

This was often a problem for me. Sometimes you are able to add keys and create relationships without any problems, but often times you may have to change the keys and/or relationships in the db to make it work -- this depends on your requirements; you may have to deal with this even when using table-entities.

希望这有助于。