简体   繁体   English

在ASP.NET动态数据/ LINQ to SQL中启用主键字段的编辑

[英]Enabling editing of primary key field in ASP.NET Dynamic Data / LINQ to SQL

如果您的表具有由外键和其他表列组成的复合主键,那么如何使ASP.NET动态数据允许非外部主键表列可编辑?

即使不使用动态数据,LINQ to SQL也不支持更改实体的主键。

A primary key just has to be unique, and that doesn't necessarily mean it has to be automatically generated. 主键必须是唯一的,这并不一定意味着它必须自动生成。 Nor does it mean it can't be changed. 它也不意味着它无法改变。

It's conceivable that a human might be coming up with the primary key, in which case the pk field needs an input. 可以想象,人类可能会想出主键,在这种情况下,pk字段需要输入。

Compound or composite foreign keys are not well supported in the current version. 当前版本不支持复合或复合外键。 I ran into the same problem when building a test project. 我在构建测试项目时遇到了同样的问题。 For a parent-child relationship with a single-column foreign key, dynamic data allowed me to edit records in the child table using drop downs. 对于具有单列外键的父子关系,动态数据允许我使用下拉列表编辑子表中的记录。 For a parent-child relationship with a compound primary key, dynamic data only allowed me to edit one of the foreign keys, without a drop down. 对于具有复合主键的父子关系,动态数据仅允许我编辑其中一个外键,而不会下拉。 I tried both Linq to SQL and Data Entities. 我尝试了Linq to SQL和Data Entities。

A primary key represents the identity of an entity. 主键表示实体的标识。 It is assumed that primary key fields are never changed. 假设主键字段永远不会改变。 Your question suggests that you might be using primary keys incorrectly. 您的问题表明您可能错误地使用主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM