简体   繁体   中英

SQL Query Performance - Which approach is better if any?

I am having to return several record sets from SQL Server to constructs a C# object. While EF doesn't currently support (possibly the beta version) returning complex objects like this I am having to resort to returning a DataSet using ADO.NET to retrieve the data before transforming it into a pleasant C# representation, see below.

SELECT * FROM ...
exec dbo.usp_SP1 @ProductID,@CatalogName
exec dbo.usp_SP2 @ProductID,@CatalogName    

Its always better to make fewer database calls however due to how this query is being executed would making several requests for each DataSet be that much worst?

One database roundtrip is always better that three (or two).

Your code could be clean even with this set of queries. You just have to call DataTable.Load three times, in succession, to load all three results sets from the DbDataReader .

So yes, I recommend one bigger query and a single DataSet for all result sets.

You can reference each table result inside of a dataset . ds.Tables[index].Rows... . So I would make one call, get all the data and return it via whether you call another sproc or just a simple SELECT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM