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.
Symptoms:
When viewing the User table, I get a column on the end with 'View user addresses' linking like so: http://dev.cityslurp.com/Addresses/List.aspx?PrincipalId=18
Note:
PrincipalId is a GUID, not an int, so I think the '18' should actually be a GUID
The integer maps properly to the User.Id value
So I think the link should look like: http://dev.cityslurp.com/Addresses/List.aspx?PrincipalId=157221EF-C85C-4FDF-B861-60D149E11BFC, but following that give an error: "'DropDownList1' has a SelectedValue which is invalid because it does not exist in the
list of items. Parameter name: value" - I'm assuming this error is because the dropdown value is expecting an integer.
So even though # 3 gives me an error, I think that it's the correct queryparameter to use.
Conversely, when I go to the Address/List.aspx page, I have a column with links back to the User Details page. The links correctly show the user's email address as the text, but again the link is wrong. For example for the same user, their link FROM the
address List page is: http://dev.cityslurp.com/Users/Details.aspx?Id=157221ef-c85c-4fdf-b861-60d149e11bfc
Note:
User.Id *is* the PK for the User table
the User.Id is an integer
The Guid used is the value from the 'PrincipalId' field
Since the link contains the text of the email address, and the Guid is correct it would seem that the relationship is working, it's just that Id is wrong.
I'm assuming that the link should look like: http://dev.cityslurp.com/Users/Details.aspx?Id=70, which works to view the user details.
I'm thinking that either this maybe a bug, but surely others have successfully used one-to-many relationships using non-PK fields before?
The relationships look to be good, in that they are using the fields that I specified.
Here's an example of the relationship in the auto-generated DataAccess file:
[Table(Name="dbo.Address")]
public partial class Address : INotifyPropertyChanging, INotifyPropertyChanged
{
...
[Association(Name="Users_Address", Storage="_Users", ThisKey="PrincipalId", OtherKey="PrincipalId", IsForeignKey=true)]
public Users Users
{
get
{
TroyMcLeure
0 Points
1 Post
Foreign table List.aspx links use incorrect key for one-to-many relationships
Nov 26, 2009 12:00 AM|LINK
Hi,
I'm using LINQ to SQL with Dynamic Data.
I have two tables: Users and Addresses:
Symptoms:
When viewing the User table, I get a column on the end with 'View user addresses' linking like so: http://dev.cityslurp.com/Addresses/List.aspx?PrincipalId=18
Note:
So even though # 3 gives me an error, I think that it's the correct queryparameter to use.
Conversely, when I go to the Address/List.aspx page, I have a column with links back to the User Details page. The links correctly show the user's email address as the text, but again the link is wrong. For example for the same user, their link FROM the address List page is: http://dev.cityslurp.com/Users/Details.aspx?Id=157221ef-c85c-4fdf-b861-60d149e11bfc
Note:
I'm assuming that the link should look like: http://dev.cityslurp.com/Users/Details.aspx?Id=70, which works to view the user details.
I'm thinking that either this maybe a bug, but surely others have successfully used one-to-many relationships using non-PK fields before?
The relationships look to be good, in that they are using the fields that I specified.
Here's an example of the relationship in the auto-generated DataAccess file:
[Table(Name="dbo.Address")]
public partial class Address : INotifyPropertyChanging, INotifyPropertyChanged
{
...
[Association(Name="Users_Address", Storage="_Users", ThisKey="PrincipalId", OtherKey="PrincipalId", IsForeignKey=true)]
public Users Users
{
get
{
...
foreign key one-to-many foreign table link