实体框架|复合主键

时间:2013-06-13 14:09:22

标签: entity-framework composite-primary-key

我只需要获取实体的Composite主键。

我的实体:

public class UserRole
{
public int ID_User {get;set;}
public int ID_Role {get;set;}
}

我的实体映射:

public class UserRoleMap: EntityTypeConfiguration<UserRole>
{
// Primary Key
            this.HasKey(t => new { t。ID_User, t.ID_Role });

            // Properties
            this.Property(t => t.ID_User)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.ID_Role)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("User_Role");
            this.Property(t => t.ID_User).HasColumnName("ID_User");
            this.Property(t => t.ID_Role).HasColumnName("ID_Role");
}

我的目标是获得“ID_User”和“ID_Role”。 我真的不知道该怎么做......

感谢。 问候, 利昂娜

0 个答案:

没有答案
相关问题