Entity Framework 4.1 : The navigation property configured with One-to-One/zero mapping

5.2k Views Asked by At

Possible Duplicate:
Entity Framework 4.1 : The navigation property ‘BusinessUser’ declared on type ‘Login’ has been configured with conflicting multiplicities

I am having two entities

BusinessUser { Id(PK), Name,...}

Login { BusinessUserID(PK, FK), Email, Password, etc...}

Relationship between BusinessUser and Login is one-to-zero/one.

I am having following configurations In BusinessUser EF configuration class

this.HasOptional(bu => bu.LoginInfo)
    .WithOptionalPrincipal(l => l.BusinessUser);

In Login EF configuration class

this.HasRequired(l => l.BusinessUser)
    .WithOptional(bu => bu.LoginInfo);

I am getting following exception

The navigation property 'BusinessUser' declared on type 'Login' has been configured with conflicting multiplicities.

Where I am wrong with my one-to-one/zero configuration in EF 4.1 code first.

public class BusinessUser {
    public virtual int ID { get; set; }

    public virtual int BusinessID { get; set; }

    public virtual Business Business { get; set; }

    public Login LoginInfo { get; set; }
  }

 public class Login {
    public virtual int BusinessUserID { get; set; }

    public virtual string Email { get; set; }

    public virtual string Password { get; set; }

    public BUsinessUser BusinessUserInfo { get; set; }
  }

Also I am looking for bi-directional.

1

There are 1 best solutions below

0
On BEST ANSWER

You need to remove the following mapping from BusinessUser configuration.

this.HasOptional(bu => bu.LoginInfo)
    .WithOptionalPrincipal(l => l.BusinessUser);

Configuring the relationship in single configuration is enough. If you need to map it from BusinessUser configuration you can do it as follows.

this.HasOptional(bu => bu.LoginInfo)
    .WithRequired(l => l.BusinessUser);