如何在实体框架中将字符串作为主键! [英] How to make string as primary key in entity framework!

查看:72
本文介绍了如何在实体框架中将字符串作为主键!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含员工姓名和员工ID的旧表。现在,员工ID位于char中,因为它可以保存以字母开头的值。 Employee id是表中唯一可用的唯一字段。

I have a legacy table containing employee name and employee id. Now the employee id is in char because it can hold values starting with an alphabet. Employee id is the only unique field available in the table.

现在,我正在使用视图从表中捕获数据(它在单独的数据库中)。但是由于缺少int主键,我的实体框架拒绝识别视图。

Now I am using a view to capture the data from the table (It is in a separate database). But my entity framework is refusing to identify the view due to the lack of int primary key.

由于我无法触摸旧表,因此对此方法的任何解决方案都将受到高度赞赏。

Any solution to this would be highly appreciated as I can not touch the legacy table.

推荐答案


但是我的实体框架由于缺少int primary而拒绝识别视图

But my entity framework is refusing to identify the view due to the lack of int primary key.

我对此表示怀疑。 EF支持将字符串作为PK。

I doubt it. The EF supports strings as PKs.

但是,视图当然根本没有PK。这意味着将它们与EF一起使用时,您必须做一些额外的工作,尤其是使它们可更新时。 此处是

But views, of course, can't have PKs at all. Which means you have to do some extra work when using them with the EF, especially if you make them updatable. Here's how.

这篇关于如何在实体框架中将字符串作为主键!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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