1:1 Relations and Entity Framework

Yesterday I tried to declare a 1:1 Relation in Entity Framework. As I have to write the EDMX File by hand (for various reasons) I’ve tried a straight forward way and ran into some problems. But first let me show you the sample Model: Model What I tried in the EDMX File (or better: CSDL, MSL and SSDL): CSDL:

<association Name="FK_ParkingSpace_Employee">
<end Role="Employee" Type="Database1Model.Employee" Multiplicity="0..1" />
<end Role="ParkingSpace" Type="Database1Model.ParkingSpace" Multiplicity="0..1" />
</association>

Same in the SSDL:

<association Name="FK_ParkingSpace_Employee">
<end Role="Employee" Type="Database1Model.Store.Employee" Multiplicity="0..1" />
<end Role="ParkingSpace" Type="Database1Model.Store.ParkingSpace" Multiplicity="0..1" />
<referentialConstraint>
<principal Role="Employee">
<propertyRef Name="ID" />
</principal>
<dependent Role="ParkingSpace">
<propertyRef Name="fk_Employee" />
</dependent>
</referentialConstraint>
</association>

But that gave me this Error:
Multiplicity is not valid in Role ‘ParkingSpace’ in relationship ‘FK_ParkingSpace_Employee’. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.
What? Why? OK, I didn’t understand and could not find any information on the web how to define a 1:1 Relation in Entity Framework. So I made a small test application. And the SSDL was:

<association Name="FK_ParkingSpace_Employee">
<end Role="Employee" Type="Database1Model.Store.Employee" Multiplicity="0..1" />
<end Role="ParkingSpace" Type="Database1Model.Store.ParkingSpace" Multiplicity="*" />
<referentialConstraint>
<principal Role="Employee">
<propertyRef Name="ID" />
</principal>
<dependent Role="ParkingSpace">
<propertyRef Name="fk_Employee" />
</dependent>
</referentialConstraint>
</association>

Multiplicity=”*” Ah, OK – from the Database’s viewpoint there is no 1:1 Relation. There’s a 1:n Relation. So I have to define 1:n Relation in the SSDL too. A Constraint in the Database and in the Object Model ensures, that this 1:n Relation is a 1:1 Relation. Or am I wrong?

dasZ.at

dasZ.at - the people behind ZBox.
dasZ.at Logo

Downloads

The lateset download will be available here - soon

Lastet blog

In our blog we talk about the latest developments around our tool ZBox.
>> Blog

Latest blog entries
>> Reference project: Implementing WordPress-based Website

Based on the reference design provided by Sabine herself, we implemented the zartbitter Website. The site is powered by the PHP-based WordPress blog and CMS engine, some additional plugins and a bit of yarn to hold it all together.


>> Setting a permanent search_path, the Right Way

Others recommend setting the search_path in the postgresql.conf. Current versions of PostgreSQL can set the search_path permanently on a per-database basis without having to touch system configuration files


>> Porting Puppet to Windows

In the course of the PuppetCamp Europe, I met with many people I only knew from IRC and email and it was a great time with interesting and inspiring discussions.

Today I want to write about the work I’m currently commisioned for by puppetlabs, porting puppet to Microsoft Windows.


>> Puppetcamp Europe 2010

I’m going to Puppetcamp Europe 2010!


>> Using gendarme with Code Contracts from .NET 4.0

When using gendarme on post-processed assemblies with code contracts and /throwonfailure set, a few things have to be ignored. Put the following lines into your ignore file (for example gendarmeignore.txt) and use it with –ignore on the command line.


>> Microsoft cannot decode Base64: News at 11!

Arthur has found a really nasty bug in Microsoft’s streaming Base64 decoder as used in the WCF: Connect Bug#541494


>> Kolab Connector binaries uploaded

Arthur moved on with programming and testing. Now we uploaded the first packages, which now contain the basic calendar and contacts synchronisation. The plugins already are able to synchronize our personal data.


>> Kolab Sync for Android and Outlook: Developer Preview

We are proud to announce the first developer preview for Kolab sync clients for both Android and Outlook. Both are licensed under the GPLv3.


>> Visual Studio 2008 Debugger

I didn’t know that: the VS2008 debugger has many bugs. Specifically, if you have a solution with multiple websites, debugging doesn’t work!

Symptom: Upon reaching a breakpoint, StepOver/Into do not work, but resume execution. This makes the debugger pretty pointless.


>> Building a simple MSBuild Task

On the “Using Studio’s “Custom Tool” in MSBuild” question, I was prompted to share the code. Here is a stripped down skeleton where I removed the actual calls to the custom tool. Since it is open source I didn’t really need to access the Visual Studio’s registry keys.