I have a many-many relationship using EF database first between AspNetUser
and Order
:
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)
)
So a user needs to select a bunch of usernames, and then I want to find these users in the DB and add them to the order (these users will take ownership of that order):
using (var db = new Entities())
{
var users = db.AspNetUsers;
var user = users.FirstOrDefault(u => u.UserName == userName);
order.AspNetUsers.Add(user);
}
But I can see immediately after calling db.AspNetUsers
, there is an innerException under users.ResultsView
:
"Invalid column name 'Order_Id'."
There is no such column Order_Id
in any of my tables or in my code, and I have no idea where to start debugging this.
Order.cs (generated from 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; }
}
Here I have an Owner AspNetUser
, and then a list of other AspNetUser
s who are also associated with that order.
Where is this Order_Id
coming from? Please let me know if I need to add any more details