Reputation: 63
I've created an Entity Framework model from an existing database with no issues or warnings. I came across a table that did not generate in the code and does not appear in the model.
This table, and a few others very much like it, are very simple: 2 columns, each foreign keys and one primary key which is a composite of the two foreign keys.
I was digging around some other solutions and the closest thing I've read about is when there is no primary key on the table at all. It doesn't seem to be that issue as the XML generated looks fine and has no error message.
My table in the EDMX:
<EntityType Name="UserTaskSubscription">
<Key>
<PropertyRef Name="UserID" />
<PropertyRef Name="TaskID" />
</Key>
<Property Name="UserID" Type="int" Nullable="false" />
<Property Name="TaskID" Type="int" Nullable="false" />
</EntityType>
I've also attempted to drop and recreate the EDMX but I've had no success there either.
Any suggestions would be extremely helpful.
Upvotes: 3
Views: 2881
Reputation: 3308
It should have generated code like this:
namespace dbfirstjointable.Models
{
using System;
using System.Collections.Generic;
public partial class Task
{
public Task()
{
this.Users = new HashSet<User>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
}
}
namespace dbfirstjointable.Models
{
using System;
using System.Collections.Generic;
public partial class User
{
public User()
{
this.Tasks = new HashSet<Task>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Task> Tasks { get; set; }
}
}
No UserTask class would be necessary here. The many to many relationship is expressed through the collections on each class to the "foreign" class.
Upvotes: 5