我在AspNetUser
和Order
之间首先使用EF数据库建立了很多关系:
CREATE TABLE [dbo].[OrdersAspNetUsers] (
[AspNetUserId] nvarchar(128) NOT NULL FOREIGN KEY references [dbo].[AspNetUsers],
[OrderId] INT NOT NULL FOREIGN KEY references [dbo].[Orders],
primary key (AspNetUserId, OrderId)
)
因此用户需要选择一堆用户名,然后我想在数据库中找到这些用户并将其添加到订单中(这些用户将获得该订单的所有权):
using (var db = new Entities())
{
var users = db.AspNetUsers;
var user = users.FirstOrDefault(u => u.UserName == userName);
order.AspNetUsers.Add(user);
}
但是我可以在调用db.AspNetUsers
后立即看到,users.ResultsView
下有一个innerException:
“无效的列名称'Order_Id'。”
我的任何表格或代码中都没有这样的列Order_Id
,我不知道从哪里开始调试。
Order.cs (从DB生成)
public partial class Order
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Order()
{
this.OrderComments = new HashSet<OrderComment>();
this.AspNetUsers = new HashSet<AspNetUser>();
}
public int Id { get; set; }
public int OrganisationId { get; set; }
public string Name { get; set; }
public string OwnerId { get; set; }
public string Description { get; set; }
public decimal Value { get; set; }
public string Status { get; set; }
public string StatusDescription { get; set; }
public Nullable<System.DateTime> DeadLine { get; set; }
public Nullable<int> Progress { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OrderComment> OrderComments { get; set; }
public virtual Organisation Organisation { get; set; }
public virtual AspNetUser AspNetUser { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<AspNetUser> AspNetUsers { get; set; }
}
此处我有一个所有者AspNetUser
,然后是一个与该订单相关联的其他AspNetUser
的列表。
Order_Id
来自哪里?如果我需要添加更多详细信息,请告知我们