In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the method of Linq to sql dynamic query". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Linq to sql dynamic query is really a headache. You have to write a lot of code with expression tree or reflection method. Sometimes you might as well go back to the era of manual sql splicing instead of being so complicated, but the technology is always moving forward, and you still have to solve this problem on Linq. I have no intention of finding a relatively simple way to share it on the Internet:
Void ShowData () {using (DBDataContext db = new DBDataContext (Database.ConnectionString)) {Expression expr = n = > GetCondition (n); var _ query = db.T_Bargins.Where (expr.Compile ()) .Select (b = > new {b.F_Money, b.F_Name}) Foreach (var item in _ query) {Response.Write (item.F_Name + "" + item.F_Money.ToString () + ");}
The DynamicQuery routines of both VB and C # include a source implementation of an auxiliary library that allows you to express LINQ queries using extended methods that accept string parameters rather than class-safe language operators. You can copy the implementation of C# or VB's DynamicQuery library into your own project and use it to build Linq to sql dynamic queries based on user input where appropriate.
Linq to sql dynamic query implementation obtains the condition that the contract amount is greater than 6000, or the contract name contains the word "should".
Private bool GetCondition (T_Bargin _ Table) {bool _ result = false; decimal _ MinMoney = 6000; if (_ MinMoney > 0) {_ result | = _ Table.F_Money > = _ MinMoney;} string _ Name = "Jianghua"; if (! String.IsNullOrEmpty (_ Name)) {_ result | = _ Table.F_Name.Contains (_ Name) } return _ result;} "what is the method of Linq to sql dynamic query" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.