zengcheng / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

Multiple Schema, Same Table name produces incorrect Associations in Dbml File #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using?

Please provide any additional information below.

Original issue reported on code.google.com by likwid on 20 Oct 2008 at 10:37

GoogleCodeExporter commented 9 years ago
Hit submit by mistake.  Here are the details:

Multiple Schema, Same Table name produces incorrect Associations in Dbml File

What steps will reproduce the problem?
1. Create a database with the attached Schema
2. Generate Dbml file

What is the expected output? What do you see instead?
The attached schema contains 3 tables, dbo.Customer, dbo.Lender, and 
Test.Lender.  
Both Lender tables contain a foreign key relationship to dbo.Customer.  I would 
expect for PLINQO to output an association for each Lender table.

Instead what happens is PLINQO attempts to merge the two relationships into a 
single 
Association.  This produces incorrect results in the Dbml.

Here is the incorrect output:
<Table Name="dbo.Customer" Member="Customer">
<Type Name="Customer">
  <Column Name="Id" Storage="_id" Type="System.Int32" DbType="int NOT NULL IDENTITY" 
IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
  <Column Name="Name" Storage="_name" Type="System.String" DbType="nchar(10)" 
CanBeNull="true" />
  <Association Name="Customer_Lender" Member="IdLenderlist" Storage="_idLenderlist" 
ThisKey="Id,Id" OtherKey="CustomerId,CustomerId" Type="Lender" />
</Type>
</Table>
<Table Name="dbo.Lender" Member="Lender">
<Type Name="Lender">
  <Column Name="Id" Storage="_id" Type="System.Int32" DbType="int NOT NULL IDENTITY" 
IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
  <Column Name="CustomerId" Storage="_customerId" Type="System.Int32" DbType="int NOT 
NULL" CanBeNull="false" />
  <Column Name="Name" Storage="_name" Type="System.String" DbType="nchar(10)" 
CanBeNull="true" />
  <Association Name="Customer_Lender" Member="IdCustomer" Storage="_idCustomer" 
ThisKey="CustomerId,CustomerId" OtherKey="Id,Id" Type="Customer" 
IsForeignKey="true" 
DeleteOnNull="true" />
</Type>
</Table>
<Table Name="Test.Lender" Member="Lender1">
<Type Name="Lender1">
  <Column Name="Id" Storage="_id" Type="System.Int32" DbType="int NOT NULL IDENTITY" 
IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
  <Column Name="CustomerId" Storage="_customerId" Type="System.Int32" DbType="int NOT 
NULL" CanBeNull="false" />
  <Column Name="Name" Storage="_name" Type="System.String" DbType="nchar(10)" 
CanBeNull="true" />
</Type>
</Table>

Here is what I would expect to see:
 <Table Name="dbo.Customer" Member="Customer">
    <Type Name="Customer">
      <Column Name="Id" Storage="_id" Type="System.Int32" DbType="int NOT NULL 
IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
      <Column Name="Name" Storage="_name" Type="System.String" DbType="nchar(10)" 
CanBeNull="true" />
      <Association Name="Customer_Lender" Member="LenderList" Storage="_lenderList" 
ThisKey="Id" OtherKey="CustomerId" Type="Lender" />
      <Association Name="Customer_Lender1" Member="Lender1List" 
Storage="_lender1List" ThisKey="Id" OtherKey="CustomerId" Type="Lender1" />
    </Type>
  </Table>
  <Table Name="dbo.Lender" Member="Lender">
    <Type Name="Lender">
      <Column Name="Id" Storage="_id" Type="System.Int32" DbType="int NOT NULL 
IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
      <Column Name="CustomerId" Storage="_customerId" Type="System.Int32" DbType="int 
NOT NULL" CanBeNull="false" />
      <Column Name="Name" Storage="_name" Type="System.String" DbType="nchar(10)" 
CanBeNull="true" />
      <Association Name="Customer_Lender" Member="Customer" Storage="_customer" 
ThisKey="CustomerId" OtherKey="Id" Type="Customer" IsForeignKey="true" 
DeleteOnNull="true" />
    </Type>
  </Table>
  <Table Name="Test.Lender" Member="Lender1">
    <Type Name="Lender1">
      <Column Name="Id" Storage="_id" Type="System.Int32" DbType="int NOT NULL 
IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
      <Column Name="CustomerId" Storage="_customerId" Type="System.Int32" DbType="int 
NOT NULL" CanBeNull="false" />
      <Column Name="Name" Storage="_name" Type="System.String" DbType="nchar(10)" 
CanBeNull="true" />
      <Association Name="Customer_Lender1" Member="Customer" Storage="_customer" 
ThisKey="CustomerId" OtherKey="Id" Type="Customer" IsForeignKey="true" 
DeleteOnNull="true" />
    </Type>
  </Table>

What version of the product are you using?
Latest from SVN

Original comment by likwid on 20 Oct 2008 at 10:49

Attachments:

GoogleCodeExporter commented 9 years ago
Well, I figured out what is causing the issue with this one as well.

If the FK relationship is named the same thing in both schemas, SchemaExplorer 
will 
find both.

I don't know if the same key in different schemas is something that 
SchemaExplorer 
can detect, but I can fix it on my end.

Original comment by likwid on 21 Oct 2008 at 2:54

GoogleCodeExporter commented 9 years ago
I found the issue in the SqlSchemaProvider.  The latest build should fix this. 
Thanks for the bug report.

Original comment by paul.wel...@gmail.com on 21 Oct 2008 at 6:13