One-to-many dynamic relationships using non-PK fields: A foreign table. List.aspx links use the wrong key for one-to-many relationships

Problem: Invalid URLs created between tables with one-to-many relationships. How can i fix this?

I am using LINQ to SQL with dynamic data.

I have two tables: users and addresses:

* 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 PK and 'PrincipalId' (Guid) as the linking key
* The Addresses table has AddressId(int) as it 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.

Symptoms

When viewing the User table, I get a column at the end with the "View user addresses" binding: http://dev.cityslurp.com/Addresses/List.aspx?PrincipalId=18

Note:

, # 3 , , .

, Address/List.aspx, . , . , FROM : http://dev.cityslurp.com/Users/Details.aspx?Id=157221ef-c85c-4fdf-b861-60d149e11bfc

:

  • User.Id PK
  • User.Id
  • - "PrincipalId"
  • , Guid , , , , .

, : http://dev.cityslurp.com/Users/Details.aspx?Id=70, .

, , " ", -PK- ?

, , .

DataAccess:

[ (Name= "dbo.Address" )]   public partial class : INotifyPropertyChanging, INotifyPropertyChanged   {

...

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

...

, ? , , - , , , .

Cheers,

+3

Source: https://habr.com/ru/post/1724042/


All Articles