我正在PostgreSQL上创建下表:
create table dbo.user_ratings (
user_id int not null,
user_rated_id int not null,
value decimal not null,
status_id int not null,
created_at timestamp with time zone not null,
updated_at timestamp with time zone null,
user_comment text null,
primary key (user_id, user_rated_id),
foreign key (user_id) references dbo.users(id),
foreign key (status_id) references dbo.status(id),
foreign key (user_rated_id) references dbo.users(id));
使用CodeFirst映射表时,我正在执行以下操作:
[Table("user_ratings", Schema="dbo")]
public class UserRating {
[Key, Column("user_id", Order = 0)]
public int UserId { get; set; }
public virtual User User { get; set; }
[Key, Column("user_rated_id", Order = 1)]
public int UserRatedId { get; set; }
public virtual User UserRated { get; set; }
[Column("status_id")]
public int StatusId { get; set; }
public virtual Status Status { get; set; }
public decimal Value { get; set; }
[Column("user_comment")]
public string UserComment { get; set; }
[Column("created_at")]
public DateTime CreatedAt { get; set; }
[Column("updated_at")]
public DateTime UpdatedAt { get; set; }
}
好吧,到目前为止,这么好。当我尝试查询某些内容时,我收到以下错误:
Column names in each table must be unique. Column name 'User_Id' in table 'user_ratings' is specified more than once.
这有什么问题?当我删除与列user_id
相关的映射时,它正在通过,但它不对。有人能帮助我吗?
谢谢大家!!!
答案 0 :(得分:0)
似乎此错误仅与SQLServer数据库有关。我的Web.config / App.config上仍然有一些SQLServer配置,这就是出现此错误的原因。如果没有SQLServer配置,错误就会消失。