I didn't run my blog for half a year. I was not very diligent, I started my own business, and I didn't have time to come. But in this small project, I used LINQ to SQL. In this case, I must search for multiple combinations of conditions. Although I have only a few research on the Expression Tree, it seems that there is no other way to study it.
This article is suitable for small data volumes. For large data
Multi-condition dynamic query of LINQ to SQL is indeed a headache. A lot of data needs to be written in the expression tree or reflection method.CodeSometimes it is better to think about this complexity than to go back to the era of manual SQL concatenation. However, technology is always moving forward, and it is still
This article is suitable for the small amount of data, for large data, need to use another way, see the next
First of all, from the Internet search, is essential, probably understand the LINQ multiple conditional combination query direction, began to start, first, write a delegate method:
Copy Code code as follows:
private bool Getcondition (FeedBack FB)
{
bool Boolresult = true;
int f
In the data query, we often encounter the need to dynamically build query conditions. Implementing this requirement with LINQ can be a bit more cumbersome than the previous concatenation of SQL statements. This paper introduces 3 kinds of methods of dynamically constructing query
criteria in the collection - foreach(Car datainchlist) the { * strings = data. Name.replace (Key,""+ key +""); $Data. Name =s;Panax Notoginseng } - } the + //judging the second condition A stringMi = Price1. Text;//take text to determine if it is empty the stringMa = price2. Text;//take text to determine if it is empty + - //first determine whether the text box is empty in the second condition
determine if it is empty42String ma = Price2. Text;//Take text to determine if it is empty4344//First determine whether the text box is empty in the second condition45if (mi! ="" ma! ="")46{47Decimal min =Convert.todecimal (Price1. Text);48decimal max = Convert.todecimal (Price2. Text); 49 50 list= list. Where (p=>p.price.value>=min p.pricemax). ToList (); 51 52 }53 54 // Specify the data source to display Span style= "color: #008080;" >55 repeater1.datasource = List; Repeater1.databind () 5
the first 8 {
9Model. Ranking = i +1;
Ten }
One Else
A {Determine if the overall score of the employee is the same as the total score for the previous employee - if(Nationalpaiming[i].totalscoure = = Nationalpaiming[i-1].totalscoure) - {
theModel. Ranking = List[i-1]. Ranking; //Same rank same - }
- Else
- {
+Model. Ranking =
The original wording:Dim db = from city in datacontext1.addresscityWhere City. Provinceid = dgvaddress (2, E.rowindex). Value.tostring,Select City. Cityid, City. Cityname.trimThe spaces in the cityname can be removed, but the column names in db change, and errors occur in the bound ComboBox.The modified wording:Dim db = from city in datacontext1.addresscityWhere City. Provinceid = dgvaddress (2, E.rowindex). Value.tostringSelect New with {. Cityid = City. Cityid,. CityName = City. Cityname.trim}
Preface
Today, I want to learn how to perform database operations, add, delete, and modify through LINQ. Preparations: first, a web project of ASP. net mvc 3.0 is established,
Create a database and table
Use [yqblog] gocreate table [DBO]. [tbguestbook] ([ID] [uniqueidentifier] not null primary key, [username] [varchar] (50) not null, [posttime] [datetime] not null, [Message] [varchar] (400) null, [isrequired] [bit] not null, [reply] [varchar] (4
In the previous article LINQ to SQL Advanced Series (vi), we mentioned dynamic queries that use object. This article on the basis of the above, and then do more in-depth extension. At the same time fix some of the above wrong places.
1, the dynamic query of object continued
The first thing to do is to change the function of find to an extension method. An exten
One day, a reader emailed me and asked me if I was interested in doing a translation application, according to the "Food Translation Court-English translation of Chinese menu" to the Chinese name into English dishes, because he often eat with foreigners, so I hope that his WP mobile phone can have one such application, and we just take this opportunity to explore LINQ to SQL queries and related optimization
Program code
The code is as follows
Copy Code
Like ' zhang% 'var data = context. People.where (person => person. Name.startswith ("Zhang"));Like '%zhang 'var data = context. People.where (person => person. Name.endswith ("Zhang"));Like '%yuan% 'var data = context. People.where (person => person. Name.indexof ("Yuan")!=-1);
The Sqlmethods.like method under the System.Data.Linq.SqlClient namespace can implement the same functionality, but can be used only in
This article is suitable for small data volumes. For large data volumes, another method is required. For more information, see the next article.First of all, searching on the internet is essential. After learning about the direction of the Multi-condition combination query of linq, you can start to do it. First, write a delegate method:Copy codeThe Code is as follows:Private bool GetCondition (FeedBack fb){
Select
Description: Query the customer's company name, address information
Query syntax:
var 构建匿名类型1 = from c in ctx.Customers select new { 公司名 = c.CompanyName, 地址 = c.Address };
Corresponding SQL:
SELECT [t0].[CompanyName], [t0].[Address] FROM [dbo].[Customers] AS [t0]
Description: Query the employee's name and
Label:In the data query, often encountered the need to dynamically build query conditions. Using LINQ to implement this requirement may be more cumbersome than stitching up SQL statements in the past. This article describes 3 ways to dynamically build query conditions at run
multiple table connection queries are often used in queries about databases, where the query functionality for LINQ is simply presented. 1, single-table query [CSharp] View plain copyvarquery = fromTcinchDb.tbclasswhereTc. ClassID = ="1" //query Form Tbclass Select New{ClassID=TC. ClassID, C
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.