Issue with 1 to 1 relations using multi-column FK/PK.

Sep 14, 2010 at 8:49 PM

I've resolve the problem myself, but I thought you would appreciate the information.

Given a table Person with a PK of Name, Age.

Given a table Wallet with a PK of Name, Age which is a FK to table Person. (A person can only have 0/1 wallets.  A wallet can only belong to one person.)


Within LinqSQLParser.Generated.cs the following code is created:

private void RemapParentChild()
  if (fromClause.TableName == "Walet")
      new LinqSQLFromClause(
        "Person", GetSchema("Person"), newAlias, "ON [" + fromClause.Alias + "].[Name] = [" + newAlias + "].[Name]"));[" + fromClause.Alias + "].[Age] = [" + newAlias + "].[Age]"));
        childTables[childTables.Count - 1].AnchorAlias = "CodingSummary";

This is fixed by replacing [" + newAlias + "].[Name]"));[" + fromClause.Alias + "] with [" + newAlias + "].[Name] AND [" + fromClause.Alias + "]

On a related note, I've noticed large If (X) else if (Y) else if (Z) blocks in the generated code.  Is there any reason you didn't go with Switch/Case blocks?
Sep 15, 2010 at 1:54 AM

I am a little confused. I assume you are using the NHDAL not the EFDAL, but I did not find an issue with this specific piece of code. I did find an order issue when calling creating a PrimaryKey object of a type with a composite key but I do not think this is what you are talking about. Are you having problem running the code or compiling the code? I actually cannot find this exact code anywhere in the project. Will you point me to the exact spot. A model and or your code would be very helpful if you could send it to If you are changing the source please get latest.

Sep 15, 2010 at 5:18 PM

For those following along who won't get to see my Email:

1. I am using NHDAL rather then EFDAL.

2. (obviously) I used fake columns/tables for this example rather than the real tables/columns codetools will see in my model.

3. My model was created by importing an existing database (I'm evaluating nHydrate as a new DAL generation tool by comparing it to our current process).

4. The file LinqSQLParser.Generated.cs is in the root DAL project (CompanyName.ProjectName) at the root of said project.

5. Forgot to send this in the Email: I am using the 3.6 download.

Sep 15, 2010 at 6:56 PM

I'm interested in what you find, codetools.

In addition, now that I'm moving past the "I can get the code to look/test right" I'm moving on to working with the versioning and finding a similar problem in the generated sql scripts:

... INNER JOIN [Person] on [Wallet].[Name] = [Person].[Name], [Wallet].[Age] = [Person].[Age] ...

Where the comma needs to be replaced with AND

If this is a bug in the code, I'm glad I helped you find it.  If it's a bug in how I build my model, I'm eager to learn how to do it better.  In any case, the project I'm evaluating this for has 3 databases which already exist, so I'm sure I'll be pushing nHydrate to it's limits in one way or another ;)