Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

sql server - UDT as a parameter in EF4 query

I know that EF4 does not support User Defined Table Types (yet). I need to write a query, that accepts a list of pairs <product_code, quantity> and returns a record set with product_code and price for each product_code passed, based on quantity. What is my best option with EF4 to model this? The calculation in the database to get the price are quite complex, and there are a lot of products, which means that most of the action should happen server-side. (For example I can't get full list of prices from server first and then filter to the products I need on the client. I also can't apply quantity to the calculation on the client, that has to be passed to server and processed there). Any thoughts are welcome.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you mostly answered your question. Computation must be done on the database server and you just want to get result, don't you? If you are using SQL Server 2008 you can create stored procedure which accepts table valued parameter. Now you can call this procedure either directly using ADO.NET or using EF and context.ExecuteStoreQuery where you still pass DataTable to SqlParameter with SqlDbType.Structured.

If you don't use SQL Server 2008 you need stored procedure with one big nvarchar parameter passing whole list as comma delimited string. Your stored procedure will first parse this list to temporary table and then process the computation in the same way as with table valued parameter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...