【发布时间】:2012-12-27 17:27:14
【问题描述】:
我正在尝试创建一个TestMethod,它将枚举我的数据上下文中的表并尝试从每个表中读取一条记录。测试的目标是确保我的 .dbml 文件与底层数据库同步。到目前为止我所拥有的:
[TestMethod]
public void TestDataContextTables()
{
using ( MyDataContext dataContext = new MyDataContext() )
{
int count = 0;
IEnumerable<MetaTable> tableList = dataContext.Mapping.GetTables();
foreach ( MetaTable table in tableList )
{
Debug.Print( "Testing " + table.TableName + "..." );
// method to restore >= 1 record using LINQ...
//Object dummy = from t in dataContext.Mapping.GetTables().Skip( count ).Take( 1 ) select t; <-- wrong (1)
//Object dummy = from t in dataContext.Mapping.GetTable( table.RowType.GetType() ) select t; <-- also wrong (2)
//Object dummy = from t in dataContext.Mapping.GetTable( table.RowType.GetType() ).GetType() select t; <-- also wrong (3)
Debug.Print( "OK\n" );
count++;
}
}
}
LINQ 语句 (1) 似乎没有读取任何实际数据。 LINQ 语句 (2) 给出了编译时错误“找不到源类型 'MetaTable' 的查询模式的实现”,并且 (3) 给出了错误“找不到源类型的查询模式的实现” '系统类型'”。后两者告诉我,当我应该指的是 something 时,我指的是元 something。
我正在寻找的是一种在 LINQ 语句中引用 DataContext 中的每个表并从每条记录中返回一行以确保 LINQ 生成与底层数据库的 jibes 的 SELECT 的方法。
【问题讨论】:
标签: c# linq datacontext loops