Is there any possibility to set OneToOne relation (cardinality) when generate dbml with SQLMetal? By default dbml schema generated with the OneToMany relation.
+1
A:
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
2010-02-03 14:51:01
Yes, I can use DBML designer, but I want to automate this process!
Sasha
2010-02-04 16:49:58
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
2010-02-05 09:30:41
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
2010-02-07 13:32:08
A:
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
2010-02-04 15:41:37
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
2010-02-05 09:52:01