google-code-export / dblinq2007

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

dbmetal doesn't handle foreign keys on multiple columns in Oracle #195

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
In Oracle create a schema with two tables and foreign key between them with
multiple columns in the key:

create user user1 identified by user1;
grant dba to user1;
connect user1/user1
create table a (x number, y number, constraint a_pk primary key (x, y));
create table b (id number, a_x number, a_y number, constraint b_pk primary
key (id),
constraint b_a_fk foreign key (a_x, a_y) references a (x, y));

Run dbmetal on the schema:

DbMetal.exe /provider:oracle /conn:"Data
Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1
521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)));User
Id=user1;Password=user1;" /database=user1 /dbml:test.dbml

DbMetal.exe test.dbml /code:test.cs

What is the expected output? What do you see instead?
The expected result is that the code file is created without error.

The actual result is the exception (edited for readability). It seems to
mean that multiple constraints with the same name exist. Looking at the
dbml file, it seems one constraint is generated for each column:
DbMetal failed:System.InvalidOperationException: Sequence contains more
than one element
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1)
   at DbLinq.Util.DbmlExtensions.GetReverseAssociation(Database, Association)
      in ...\src\DbLinq\Util\DbmlExtensions.cs:line 53
   at DM.G.I.CTG.CodeGenerator.WriteClassChildrenAttachment(CodeWriter,
Table, Database, GenerationContext)
      in ...\src\DM\G\I\CTG\CodeGenerator.Class.cs:line 720
   at DM.G.I.CTG.CodeGenerator.WriteClass(CodeWriter, Table, Database,
GenerationContext)
      in ...\src\DM\G\I\CTG\CodeGenerator.Class.cs:line 91
   at DM.G.I.CTG.CodeGenerator.WriteClasses(CodeWriter, Database,
GenerationContext)
      in ...\src\DM\G\I\CTG\CodeGenerator.Class.cs:line 58
   at DM.G.I.CTG.CodeGenerator.Write(TextWriter, Database, GenerationContext)
      in ...\src\DM\G\I\CTG\CodeGenerator.cs:line 107
   at DM.G.I.Processor.GenerateCode(Parameters, Database, ISchemaLoader,
String)
      in ...\src\DM\G\I\Processor.cs:line 203
   at DM.G.I.Processor.WriteSchema(Database, ISchemaLoader, Parameters)
      in ...\src\DM\G\I\Processor.cs:line 148
   at DM.G.I.Processor.ProcessSchema(Parameters)
      in ...\src\DM\G\I\Processor.cs:line 112

What version of the product are you using? On what operating system?
The problem can be reproduced using both the 0.19 release and current
svn-version (revision 1304).

Please provide any additional information below.
The problem seems that constraints with multiple columns in the key is not
handled in the Oracle provider. The attached patch hacks it in, so that the
columns are retrieved into a list (in the correct order) and stored
comma-separated in the dbml-file. This seems to be way it is handled at
least for the AssociationAttribute: "For multiple members, use a
comma-separated list.":
http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.associationattr
ibute.thiskey.aspx

Original issue reported on code.google.com by anders...@gmail.com on 2 Feb 2010 at 9:33

Attachments:

GoogleCodeExporter commented 9 years ago
Note that by accident this patch also contains the change that was included in 
the
patch for issue 194

Original comment by anders...@gmail.com on 2 Feb 2010 at 9:58

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1308.

Original comment by jonmpr...@gmail.com on 10 Mar 2010 at 4:46

GoogleCodeExporter commented 9 years ago
Closing.

Original comment by jonmpr...@gmail.com on 9 Apr 2010 at 7:55

GoogleCodeExporter commented 9 years ago
this is happening on MYSQL too for what I can tell

Original comment by alfredo....@gmail.com on 7 Oct 2010 at 6:39