Hi, I'm trying to do a one-to-one relationship, with the navigation property just on one side.
public class User {
public int UserId { get; set; } //PK
public int RankId { get; set; } //FK
public virtual Rank { get; set; } //Navigation
}
public class Rank {
public int RankId { get; set; }
}
Configuration:
public class RankConfiguration : EntityTypeConfiguration<Rank>
{
public RankConfiguration()
{
HasKey(e => e.RankId);
Property(e => e.RankId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
}
}
public class UserConfiguration : EntityTypeConfiguration<User>
{
public UserConfiguration ()
{
// PK
HasKey(e => e.UserId);
Property(e => e.RankId)
.IsRequired();
HasRequired(e => e.Rank)
.WithRequiredDependent()
.WillCascadeOnDelete(true);
}
}
For what I see (and for the little I know), db is correctly generated, but I get this error:
A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'UserId'.
I have no idea why and what is wrong .. any help? many thanks in advance
For what I see (and for the little I know), db is correctly generated, but I get this error:
A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'UserId'.
I have no idea why and what is wrong .. any help? many thanks in advance
Hi,
This error says that UserId is used as foreign key (= dependent property) in some relation which is not allowed because only properties with StoreGeneratedPattern.None can be used as foreign key. Please try to check it.
If you have any other problem, please let me know.
Best Regards,
Amy Peng
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Nerlaleph
Member
37 Points
89 Posts
EF5 one-to-one without navigation
Feb 20, 2013 09:48 PM|LINK
Hi, I'm trying to do a one-to-one relationship, with the navigation property just on one side.
public class User { public int UserId { get; set; } //PK public int RankId { get; set; } //FK public virtual Rank { get; set; } //Navigation } public class Rank { public int RankId { get; set; } }Configuration:
public class RankConfiguration : EntityTypeConfiguration<Rank> { public RankConfiguration() { HasKey(e => e.RankId); Property(e => e.RankId) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); } }public class UserConfiguration : EntityTypeConfiguration<User> { public UserConfiguration () { // PK HasKey(e => e.UserId); Property(e => e.RankId) .IsRequired(); HasRequired(e => e.Rank) .WithRequiredDependent() .WillCascadeOnDelete(true); } }For what I see (and for the little I know), db is correctly generated, but I get this error:
A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'UserId'.
I have no idea why and what is wrong .. any help? many thanks in advance
Amy Peng - M...
Star
10199 Points
964 Posts
Microsoft
Re: EF5 one-to-one without navigation
Feb 22, 2013 06:37 AM|LINK
Hi,
This error says that UserId is used as foreign key (= dependent property) in some relation which is not allowed because only properties with StoreGeneratedPattern.None can be used as foreign key. Please try to check it.
If you have any other problem, please let me know.
Best Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store