Is there any possibility to set OneToOne relation (cardinality) when generate dbml with SQLMetal? By default dbml schema generated with the OneToMany relation.
Asked
Active
Viewed 1,358 times
2
-
is the relationship pointing at the primary key on both tables? Or does the secondary table have a different primary key and the relationship is going to a foreign key column? – Agent_9191 Dec 16 '09 at 18:06
-
Relationship pointing at the primary key on both tables. – Sasha Dec 17 '09 at 12:53
2 Answers
2
Are you using the DBML designer? If so you should be able to right-click the arrow that represents the relationship and select Properties. The Cardinality property can then be set in the properties dialog to OneToOne.

Richard Ev
- 52,939
- 59
- 191
- 278
-
-
If you want *all* relationships to be OneToOne you could write a script of some description to parse the DBML file (which is just XML) for `Association` elements, and to add an attribute `Cardinality="One"` to each element. – Richard Ev Feb 05 '10 at 09:30
-
In my case I need only two relations to be OneToOne. But it seems that in any case I will write some sort of script. – Sasha Feb 07 '10 at 13:32
0
I use SqlMetal to produce a Dbml file, and then i use a xslt to modify the content of it(using this xslt base: http://blogs.msdn.com/ploeh/archive/2008/04/10/AutomaticallyGeneratingLINQToSQLModelsFromTSQL.aspx), eg. changing the cardinality or changes the type for Enums.

Carl Hörberg
- 5,973
- 5
- 41
- 47
-
also, it seems that linq2sql does support primarykey references from both sides, so just make one reference (just lika a normal one-to-many relationship) and set that association to cardiniality one. – Carl Hörberg Feb 05 '10 at 09:52