开发者

Subsonic 3: Strongly typed return value for stored procedures that return mixed results from different tables

Say I have a stored procedure that returns dataSet from 2 different tables. Example:

SELECT Customers.FirstName, Customers.LastName, SUM(Sales.SaleAmount) AS SalesPerCustomer
FROM Customers LEFT JOIN Sales
ON Customers.CustomerID = Sales.CustomerID
GROUP BY Customers.FirstName, Customers.LastName 

Is there any way to get a strongly typed list as a result from this stored procedure ? Something like this:

StoredProcedure sp = myDevDB.GetCustomerSales();

List<MyCust开发者_JS百科omType> resultSet = sp.ExecuteTypedList<MyCustomType>();

How and where do I define the MyCustomType class ? How do I map its properties to the actual table columns ?

thanks,mehul


I solved it by creating a class (in the same place as all my other classes, but I didn't extend IActiveRecord, it's just a vanilla class).

Make sure the property names have exactly the same name and data type as the ones in the procedure, then call db.sproc(params).ExecuteTypedList().AsQueryable(); and it populated fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜