[英]Entity Framework 5 CodeFirst - “Column names in each table must be unique.”
I'm creating the following table on PostgreSQL: 我正在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));
When mapping the table using CodeFirst, I'm doing the following: 使用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; }
}
Well, so far, so good. 好吧,到目前为止,很好。 When I try to query something, I'm getting the error below:
当我尝试查询某些内容时,出现以下错误:
Column names in each table must be unique. Column name 'User_Id' in table 'user_ratings' is specified more than once.
What is wrong with this? 这有什么问题? When I remove the mapping related to the column
user_id
, it's passing, but it's not right. 当我删除与列
user_id
相关的映射时,它正在传递,但是不正确。 Can someone help me? 有人能帮我吗?
Thank you all!!! 谢谢你们!!!
Seems that this error is related only to SQLServer databases. 似乎此错误仅与SQLServer数据库有关。 I still had some SQLServer configurations on my Web.config/App.config, that's why this error was appearing.
我的Web.config / App.config上仍然有一些SQLServer配置,这就是出现此错误的原因。 Without SQLServer configurations, the error is gone.
没有SQLServer配置,错误就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.