How to map a 0..1 to 1 relationship in Entity Framework 3

Posted by sako73 on Stack Overflow See other posts from Stack Overflow or by sako73
Published on 2010-04-08T14:30:06Z Indexed on 2010/04/08 14:33 UTC
Read the original article Hit count: 236

Filed under:

I have two tables, Users, and Address. A the user table has a field that maps to the primary key of the address table. This field can be null.

In plain english, Address exist independent of other objects. A user may be associated with one address. In the database, I have this set up as a foreign key relationship.

I am attempting to map this relationship in the Entity Framework. I am getting errors on the following code:

<Association Name="fk_UserAddress">
      <End Role="User" Type="GenesisEntityModel.Store.User" Multiplicity="1"/>
      <End Role="Address" Type="GenesisEntityModel.Store.Address" Multiplicity="0..1" />
      <ReferentialConstraint>
        <Principal Role="Address">
          <PropertyRef Name="addressId"/>
        </Principal>
        <Dependent Role="User">
          <PropertyRef Name="addressId"/>
        </Dependent>
      </ReferentialConstraint>
    </Association>

It is giving a "The Lower Bound of the multiplicity must be 0" error.

I would appreciate it if anyone could explain the error, and the best way to solve it.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about entity-framework