views:

11

answers:

1

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.

A: 

The reason for the error is because the table with the foreign key (User) potentially has a multiplicity greater than the primary (Address) table. The database relationship you describe in the first paragraph is 1 Address - to 0 or many Users. The EF relationship can't have zero as an option for the Primary table.

DShultz