【发布时间】:2018-09-30 20:30:37
【问题描述】:
尝试使用 Linq 对来自 SQL Server 和 Excel 的数据创建内部联接。我可以独立查询每个来源,但在加入来源时会出错。返回的错误是
不支持返回自引用常量表达式的 IQueryable。
这是什么意思,我该如何解决这个问题?
/// <summary>
/// LINQ inner join to Excel query
/// Sends the results of the query to a dataGridView.
/// Requires a DATAContext to talk to SQL Server.
/// Uses Linq to Excel to talk to Excel
/// </summary>
private void QueryDatabase()
{
var excelFile = @"C:\Test\Cad_Database.xlsx";
var excel = new ExcelQueryFactory(excelFile);
GdaDataContext gda= new GdaDataContext();
var query = from f in gda.DirectoryAnalysis
join e in excel.Worksheet("Sheet1") on f.Fullname equals e["FullPath"]
select new
{
f.Fullname,
f.Name,
ExcelFullName = e["FullPath"],
DrawingTitle = e["Drawing Title"],
DrawingNumber = e["Drawing Number"],
DrawingDate = e["Drawing Date"],
VendorName = e["Vendor Name"],
f.DA_Id
};
foreach (var item in query)
{
LogWriter.LogEvent($"{item.Fullname} {item.ExcelFullName} {item.DrawingTitle} {item.DrawingTitle}", "InnerJoinLinqToExcel");
}
dataGridView1.DataSource = query;
}
【问题讨论】:
标签: c# excel linq datacontext