我如何转换这个导致SQL到MySQL的多重?

时间:2011-03-11 01:53:03

标签: entity-framework

T-SQL

USE [AdventureWorks];
SELECT p.* FROM Production.ProductCategory cat ,[Production].[ProductSubcategory] sub, [Production].[Product] p
WHERE cat.ProductCategoryID=1 AND sub.ProductCategoryID = cat.ProductCategoryID and p.ProductSubcategoryID = sub.ProductSubcategoryID

我想转换为eSQL for EntityDatasource

<asp:EntityDataSource ID="ProductDataSource" runat="server"  ConnectionString="name=AdventureWorksEntities" 
    DefaultContainerName="AdventureWorksEntities"  EntitySetName="Product" 
    Where="EXISTS(SELECT VALUE cat FROM ProductCategory AS cat WHERE cat.ProductCategoryID=1) 
             AND EXISTS(SELECT VALUE sub FROM ProductSubcategory AS sub WHERE sub.ProductCategoryID = cat.ProductCategoryID) 
             AND it.ProductSubcategoryID = sub.ProductSubcategoryID) " 
    >
</asp:EntityDataSource>

但这是错误的。

更新 谢谢devart的提示, 我将查询修改为

SELECT VALUE p FROM AdventureWorksEntities.ProductCategory AS cat, AdventureWorksEntities.ProductSubcategory AS sub, AdventureWorksEntities.Product AS p WHERE cat.ProductCategoryID=1 AND sub.ProductCategoryID = cat.ProductCategoryID and p.ProductSubcategoryID = sub.ProductSubcategoryID

现在就可以了。

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码选择EntityDataSource事件处理程序,例如:

string query = @"SELECT VALUE p FROM EntityContainer.ProductCategory as cat, EntityContainer.ProductSubcategory as sub, EntityContainer.Product as p WHERE cat.ProductCategoryID=1 AND sub.ProductCategoryID = cat.ProductCategoryID and p.ProductSubcategoryID = sub.ProductSubcategoryID";
EntityDataSource source = null; 
source = Page.FindControl("ProductDataSource") as EntityDataSource;
if(source != null) {
  source.EntitySetName = null;
  source.CommandText = query;
}  

此代码提供强类型结果并使用Where子句。