简体   繁体   English

实体框架5 CodeFirst-“每个表中的列名必须唯一。”

[英]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.

相关问题 Entity Framework Core 错误“每个表中的列名必须是唯一的” - Entity Framework Core error "Column names in each table must be unique" 实体框架:迁移每个表中的列名必须是唯一的 - Entity Framework: migration Column names in each table must be unique 每个表中的列名必须是唯一的。 表 'dbo.Foos' 中的列名 'StripeRecipientId' 被指定多次 - Column names in each table must be unique. Column name 'StripeRecipientId' in table 'dbo.Foos' is specified more than once 每个表中的列名必须唯一。 表“ UserLogins”中的列名“ department_Id”已多次指定 - Column names in each table must be unique. Column name 'department_Id' in table 'UserLogins' is specified more than once 错误:每个表中的列名必须是唯一的 - Error: Column names in each table must be unique 如何在Codefirst实体框架中显式将属性映射到数据库表列 - How to map a property to database table column explicitly in codefirst Entity framework 模式中的每个类型名称都必须是唯一的。 代码优先 - Each type name in a schema must be unique. Code first 添加表代码优先迁移实体框架 - add table codefirst migration entity framework EF5代码优先迁移:使用RenameColumn后,“每个表中的列名必须是唯一的”错误 - EF5 Code First Migrations: “Column names in each table must be unique” error after using RenameColumn 使用Entity Framework CodeFirst映射表和视图 - Map table and views with Entity Framework CodeFirst
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM