views:

242

answers:

2

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
Yes, I can use DBML designer, but I want to automate this process!
Sasha
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
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
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
Thanks I will try your approach.
Sasha
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