C# 无效的列名实体框架列已重命名
我正在为数据库制作一个带有asp.net api的android应用程序。我在使用web服务执行某些操作时出错 发生了一个错误C# 无效的列名实体框架列已重命名,c#,asp.net,entity-framework,C#,Asp.net,Entity Framework,我正在为数据库制作一个带有asp.net api的android应用程序。我在使用web服务执行某些操作时出错 发生了一个错误 列名“Location\u Id”无效 列名“ApplicationUser\u Id”无效 我检查了迁移以及为什么我使用Location\u Id而不是LocationId?还有User\u Id AddColumn("dbo.Locations", "Location_Id", c => c.Guid()); DropColumn("dbo.Locatio
列名“Location\u Id”无效
列名“ApplicationUser\u Id”无效 我检查了迁移以及为什么我使用
Location\u Id
而不是LocationId
?还有User\u Id
AddColumn("dbo.Locations", "Location_Id", c => c.Guid());
DropColumn("dbo.Locations", "UserId");
RenameIndex(table: "dbo.Locations", name: "IX_User_Id", newName: "IX_ApplicationUser_Id");
RenameColumn(table: "dbo.Locations", name: "User_Id", newName: "ApplicationUser_Id");
CreateIndex("dbo.Locations", "Location_Id");
AddForeignKey("dbo.Locations", "Location_Id", "dbo.Locations", "Id");
在我的域中,我没有用下划线键入LocationId
以下是我的位置域:
[MaxLength(50)]
public string Name { get; set; }
[MaxLength(150)]
public string Address { get; set; }
[MaxLength(250)]
public string Description { get; set; }
public Guid UserId { get; set; }
public ApplicationUser User { get; set; }
public virtual ICollection<UserLocation> UserLocations { get; set; }
public virtual ICollection<Storage> Storages { get; set; }
[最大长度(50)]
公共字符串名称{get;set;}
[MaxLength(150)]
公共字符串地址{get;set;}
[最大长度(250)]
公共字符串说明{get;set;}
公共Guid用户标识{get;set;}
公共应用程序用户{get;set;}
公共虚拟ICollection用户位置{get;set;}
公共虚拟ICollection存储{get;set;}
我的位置上没有位置Id。只有Id。我不知道如何更改迁移或实体框架中的列。有人能帮忙吗
谢谢:)按惯例是这样的,但实际上您可以使用
[Table(“MyTable”)]
属性作为表名,使用[Column(“ColumnName”)]
属性作为列名来控制它
以下是一个例子:
[Table("Affiliates")]
public class Affiliates
{
[Column("AffiliateGUID")]
public Guid AffiliateId { get; set; }
}
按惯例是这样的,但实际上您可以通过使用
[Table(“MyTable”)]
属性作为表名和[Column(“ColumnName”)]
属性作为列名来控制它
以下是一个例子:
[Table("Affiliates")]
public class Affiliates
{
[Column("AffiliateGUID")]
public Guid AffiliateId { get; set; }
}
您可能错过了通过属性或关系设置的表。您可以查看这个问题,它可能会很有帮助。您可能错过了通过属性或关系设置的表。你们可以看看这个问题,这可能会很有帮助。为什么我有Location\u Id--因为这是默认的命名约定,您没有在映射或数据批注中覆盖它。为什么我有Location\u Id--因为这是默认的命名约定,您没有在映射或数据批注中覆盖它。我应该将它放在哪里?在locations.cs?@YeremiaDanang是的,正确,相应地命名这些,看看它是否有效。我应该把它放在哪里?在locations.cs?@YeremiaDanang是正确的,请相应地命名这些位置,并查看其是否有效。