如何将实体框架与没有主键的表或不具有相关性的表一起使用 [英] How to use entity framework with table that not have primary key or tables not haverelations

查看:92
本文介绍了如何将实体框架与没有主键的表或不具有相关性的表一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

如何将实体框架与没有主键的数据库表一起使用。



i有SQL Server 2012制作的旧数据库我需要以实体身份工作



框架技术和mvc。



i突然发现更多的桌子没有有主键



并且某些表之间没有相互关系



这样如何解决那个问题。



我尝试了什么:



我试试数据库有所有表主键

但如果我这样做我将面临什么问题

Problem
How to use entity framework with database tables that not have primary key.

i have old database made by SQL server 2012 i get requirement to work as entity

framework technique and mvc .

i suddenly found that more tables not have primary keys

and no relation ship between some tables for each other

so that how to solve that problem .

What I have tried:

I try with database have all tables primary key
but if i do that what problem i will face

推荐答案

简单。你没有。



如果没有主键,Entity Framework就无法使用该表。 EF必须有一种方法来唯一地识别表中的每个记录,这意味着拥有主键。



真的,你甚至不想使用表 没有一些ORM就没有钥匙。这可能是一个令人头疼的噩梦。



不要试图解决这样的情况。只需修复数据模型并将键添加到没有它们的表中。
Simple. You don't.

If there's no primary key, Entity Framework can't use the table. EF MUST have a way to uniquely identify every record in the table, and that means having primary keys.

Really, you don't even want to work with "tables" that don't have keys without some ORM. It can be an elephanting nightmare to deal with.

Do not attempt to "work around" a condition like this. Just fix the data model and add keys to the tables that don't have them.


这篇关于如何将实体框架与没有主键的表或不具有相关性的表一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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