更新数据模型业务实体
我有一个网络应用程序,我使用 linq to Business entites 我有业务数据模型。
问题是:
我有一个包含一列的表,它不允许空值,当我尝试更新该表时,出现以下错误: 错误属性“eg Carrier”是对象关键信息的一部分,无法修改
我能做什么?
I have web application where Iam using linq to business entites i have business data model.
the problem is :
I have table with one column that it dosen't allow null value, when I try to update this table the folloeing error arise:
error The property 'e.g Carrier' is part of the object's key information and cannot be modified
what I can do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是将第二列添加到具有唯一键(例如 guid)的表中,并在与其对应的实体上创建一个只读属性。
Linq to Business 实体需要某种密钥来跟踪数据库中要更新的内容。 通常这是数据库表上的主键。 如果您没有主键,它无法可靠地更新数据库,然后会向您发送异常。
此外,如果表上没有显式设置主键,则 linq to 业务实体将选择其中一个列(认为它是表中的第一列,但我可能是错的)作为主键,因此不允许您更新它。
The easiest thing to do is add a second column to the table that has a unique key eg guid and create a read only property on the entity that corresponds to it.
Linq to business entites needs some kind of key to keep track of what to update in the database. Usually this is the primary key on the database table. If you dont have a primary key it cannot reliably update the database and will then send you an exception.
Also if there is no primary key explicitly set on the table linq to business entites will select one of the columns (think its the first column in the table but i could be wrong) to act as a primary key and will therefore not allow you to update it.