类型"X"未映射为表 [英] The type 'X' is not mapped as a Table

查看:66
本文介绍了类型"X"未映射为表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表有ADO.NET实体数据模型,如果直接使用它,它可以很好地工作.

I have ADO.NET Entity Data Model for my tables and if I use it directly it works fine.

我想编写一个包装器,这样就不必再次重复相同的代码.最终写了一些DataContext Extension方法.

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));
}

我将此方法称为类似

System.Data.IDbConnection conn = new System.Data.SqlClient.SqlConnection("ConnectionString");
conn.Open();
dataContext = new DataContext(conn);
dataContext.Get<X>(email);

当我调用上述方法时,出现此错误:类型'X'未映射为表.

When I call the above method I get this error: The type 'X' is not mapped as a Table.

X来自ADO.NET创建的模型,无法弄清楚为什么会引发此异常.

X is coming from the model that was created by ADO.NET and unable to figure out why it's throwing this exception.

有什么想法吗?

推荐答案

真正的问题是我在Linq To Sql框架而不是Linq To Entities中使用DataContext,并且不能一起使用.

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.

说明: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆