Reputation: 384
I have ADO.NET Entity Data Model for my tables and if I use it directly it works fine.
I wanted to write a wrapper, so that I don't have to repeat the same code again. Ended up writing some DataContext Extension methods.
So, have something like this to get Data from the Table.
public static TEntity Get<TEntity>(this DataContext dataContext, object id, string primaryKeyName)
where TEntity : class, new()
{
if (id == null)
return new TEntity();
var table = dataContext.GetTable<TEntity>();
return table.Single(DynamicGet<TEntity>(primaryKeyName, id));
}
I call this method something like this
System.Data.IDbConnection conn = new System.Data.SqlClient.SqlConnection("ConnectionString");
conn.Open();
dataContext = new DataContext(conn);
dataContext.Get<X>(email);
When I call the above method I get this error: The type 'X' is not mapped as a Table.
X is coming from the model that was created by ADO.NET and unable to figure out why it's throwing this exception.
Any ideas?
Upvotes: 2
Views: 5387
Reputation: 384
The real problem is that I was using DataContext in Linq To Sql framework rather than Linq To Entities, and it cannot be used together.
Upvotes: 3
Reputation: 526
It's because the type X doesn't have a primary key in your DB. Add a primary key to the table, update your model from database and try again.
Upvotes: 0