没有公钥的EF实体 [英] EF entity without a public key

查看:114
本文介绍了没有公钥的EF实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有公钥的EF中创建一个实体。支持表具有非唯一的聚集密钥,但表中的数据在概念上没有可以使用的唯一主键。



它看起来像EF真的不喜欢这个有没有什么办法让EF接受表没有主键,并使它与它一起工作,没有性能打击?我不在乎结果是否只读。

解决方案

据了解,由于实体框架基于实体的域驱动设计概念,每个实体按定义必须具有唯一的标识符。如果您的表中的数据表示的概念在概念上不具有唯一的标识符,那么它不是框架中意图的意义上的实体。



我会定义一个存储过程,使其可以通过我的对象上下文然后通过一个延迟加载数据的类来使封装此数据的对象可用,手动将其映射到您正在使用的对象中,并以只读方式呈现。


I want to create an entity in EF without a public key. The backing table has got a non-unique clustered key, but the data in the table conceptually doesn't have a unique primary key it can use.

It looks like EF really doesn't like this. Is there any way of getting EF to accept that the table has no primary key and make it work with it anyway, with no performance hit? I don't care if the result is read-only.

解决方案

As I understand it, as the Entity Framework is based on the Domain Driven Design concept of Entities, each Entity by definition must have a unique identifier. If the concept which the data in your table represents does not conceptually have a unique identifier then it is not an Entity, in the sense intended by the framework.

With this in mind I'd define a Stored Procedure, make it available through my object context, then make the objects encapsulating this data available via a class which lazy-loads the data, manually maps it into the objects you're using and presents it in a read-only manner.

这篇关于没有公钥的EF实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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