1

我有这 2 个数据表customerTableDTcustomerAliasesTableDT. 它们都是从这样的数据库中填充的:

customerTableDT = UtilityDataAndFunctions.PerformDBReadTransactionDataTableFormat(String.Format("SELECT * FROM {0}", TableNames.customers));

customerAliasesTableDT = UtilityDataAndFunctions.PerformDBReadTransactionDataTableFormat(String.Format("SELECT * FROM {0}", TableNames.customerAliases));

现在我正在尝试对两个数据表进行内部连接,如下所示:

var customerNames = from customers in customerTableDT.AsEnumerable()
                    join aliases in customerAliasesTableDT.AsEnumerable on customers.Field<int>("CustomerID") equals aliases.Field<int>("CustomerID")
                    where aliases.Field<string>("Alias").Contains(iString) select customers.Field<string>("Name")

但它给了我这个错误:

The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'Join'.

如果我必须用 SQL 编写我想要做的事情,它非常简单:

SELECT * FROM CUSTOMERS C
INNER JOIN CustomerAliases ALIASES ON ALIASES.CustomerID = C.CustomerID
WHERE CA.Alias LIKE %STRING_HERE%

有什么帮助吗?

4

1 回答 1

5

您在 之后错过了括号AsEnumerable,因此将其视为方法组,而不是IEnumerable<DataRow>

var customerNames = from customers in customerTableDT.AsEnumerable()
                    join aliases in customerAliasesTableDT.AsEnumerable() on customers.Field<int>("CustomerID") equals aliases.Field<int>("CustomerID")
                    where aliases.Field<string>("Alias").Contains(iString) select customers.Field<string>("Name")
于 2013-04-27T21:38:03.260 回答