开发者

How do i convert this multiple where cause SQL to eSQL?

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

And i want to convert to 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>

But it is error.

Update : Thanks devart hints, I modify the query to

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

It work now.


You can use the following code for the Selecting EntityDataSource event handler, for example:

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

This code provides a strongly-typed result and uses the Where clause.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜