3

问题:在一对多关系的表之间创建的url不正确。我怎样才能解决这个问题?

我正在将 LINQ to SQL 与动态数据一起使用。

我有两个表:用户和地址:

* There is a one-to-many from Users TO Addresses ie: A user may have one or more addresses. 
* The two tables are NOT linked using their primary keys, but using a separate GUID field.
* The User table has Id (int) as it's PK and 'PrincipalId' (Guid) as the linking key
* The Addresses table has AddressId(int) as it's PK and 'PrincipalId' (Guid) as the linking key
* 'PrincipalId' is unique in the user table.
* The 'Association' looks good in the DataAccess class, and was done using the dbml designer.

症状:

查看用户表时,我在最后得到一列“查看用户地址”链接,如下所示:http ://dev.cityslurp.com/Addresses/List.aspx?PrincipalId=18

笔记:

  1. PrincipalId 是 GUID,而不是 int,所以我认为“18”实际上应该是 GUID
  2. 整数正确映射到 User.Id 值
  3. 所以我认为链接应该如下所示:http://dev.cityslurp.com/Addresses/List.aspx?PrincipalId=157221EF-C85C-4FDF-B861-60D149E11BFC,但随后给出错误:“'DropDownList1'有SelectedValue 无效,因为它不存在于项目列表中。参数名称:值“-我假设此错误是因为下拉值需要一个整数。

所以即使#3 给了我一个错误,我认为它是正确的查询参数。

相反,当我转到 Address/List.aspx 页面时,我有一列包含返回用户详细信息页面的链接。链接正确地将用户的电子邮件地址显示为文本,但链接又是错误的。例如对于同一用户,他们从地址列表页面的链接是:http ://dev.cityslurp.com/Users/Details.aspx?Id=157221ef-c85c-4fdf-b861-60d149e11bfc

笔记:

  1. User.IdUser 表的 PK
  2. User.Id 是一个整数
  3. 使用的 Guid 是“PrincipalId”字段中的值
  4. 由于链接包含电子邮件地址的文本,并且 Guid 是正确的,因此关系似乎正常,只是 Id 是错误的。

我假设该链接应如下所示:http://dev.cityslurp.com/Users/Details.aspx?Id=70,用于查看用户详细信息。

我在想这可能是一个错误,但肯定其他人之前已经成功地使用了非 PK 字段的一对多关系?

这些关系看起来很好,因为它们使用了我指定的字段。

以下是自动生成的 DataAccess 文件中的关系示例:

[Table(Name="dbo.Address")] 公共部分类地址:INotifyPropertyChanging,INotifyPropertyChanged {

...

 [Association(Name="Users_Address", Storage="_Users", ThisKey="PrincipalId", OtherKey="PrincipalId", IsForeignKey=true)]
    public Users Users
    {
        get
        {

...

有什么想法吗?我知道我可以为用户和地址创建自定义列表页面,但我正在寻找一种更简单的方法——也许在其中一个部分类上放置一个属性来告诉他们正确做什么。

干杯,兰斯

4

0 回答 0