I am working on a project today. There is such a broken word IDs varchar (100)
When a list <string> ("16", "17") is passed in. In IDs, you need to find that IDs contains 16 or 17 broken words.
IDS stores such data. 16, 17
1, 2
3, 16
Okay... There are two methods. One is to use labmber and the other is to use SQL
Labmber:
Code
Parameterexpression parameter = expression. parameter (typeof (productinfo), "T ");
Expression prop = expression. Property (parameter, "categoryid ");
Expression exp = NULL;
Foreach (string s in productcategoryids)
{
Expression current = expression. Call (
Prop, typeof (string). getmethod ("startswith", new type [] {typeof (string)}), expression. Constant (S + ","));
Exp = (exp = NULL? Current: expression. Or (exp, current ));
Current = expression. Call (
Prop, typeof (string). getmethod ("contains"), expression. Constant ("," + S + ","));
Exp = (exp = NULL? Current: expression. Or (exp, current ));
Current = expression. Call (
Prop, typeof (string). getmethod ("endswith", new type [] {typeof (string)}), expression. Constant ("," + s ));
Exp = (exp = NULL? Current: expression. Or (exp, current ));
Current = expression. Equal (prop, expression. Constant (s ));
Exp = (exp = NULL? Current: expression. Or (exp, current ));
}
Expression <func <productinfo, bool> Lambda = expression. Lambda <func <productinfo, bool> (exp, parameter );
VaR productlist = Dc. productsinfo. Where (lambda );
In this way, you can. Productlist is an SQL statement .. But not executed. If you want to use multiple conditions or the like, you can directly set where to OK.
Type 2: Use stored procedures. First write a separator Method
Code
Set ansi_nulls on
Set quoted_identifier on
Go
Alter procedure [DBO]. [product_getproductbyid]
@ Strwhere nvarchar (500 ),
@ Pagesize Int = 100,
@ Pageindex Int = 1
As
Declare @ SQL nvarchar (4000) -- subject sentence
Set @ SQL ='
Begin
With temptbl as (select *,
Row_number () over (order by productcode ASC) as row from g_product where 1 = 1' + @ strwhere + ')
Select * From temptbl where row between (@ pageindex-1) * @ pagesize + 1 and (@ pageindex-1) * @ pagesize + @ pagesize
End
'
Exec sp_executesql @ SQL, n' @ pageindex int, @ pagesize int'
, @ Pageindex, @ pagesize
Write a paging record.
Code
Alter procedure [DBO]. [product_getproductbyid]
@ Strwhere nvarchar (500 ),
@ Pagesize Int = 100,
@ Pageindex Int = 1
As
Declare @ SQL nvarchar (4000) -- subject sentence
Set @ SQL ='
Begin
With temptbl as (select *,
Row_number () over (order by productcode ASC) as row from g_product where 1 = 1' + @ strwhere + ')
Select * From temptbl where row between (@ pageindex-1) * @ pagesize + 1 and (@ pageindex-1) * @ pagesize + @ pagesize
End
'
Exec sp_executesql @ SQL, n' @ pageindex int, @ pagesize int'
, @ Pageindex, @ pagesize
In this way, you can. Directly drag the stored procedure to dbml. Because directly dragging the above will become int type. You need to change the dbml method.
I wanted to send it to the home page. However, the homepage is too demanding. Besides, there is no advanced technology.
A summary of the project .. Haha... OK 88