var db = new ExamdaDbContext(EnmDb.ExamSystem_Set); IQueryable<ExpressionClassModel> cities = db.ExpresstionClass; ParameterExpression param = Expression.Parameter(typeof(ExpressionClassModel), "c"); Expression left = Expression.Property(param, typeof(ExpressionClassModel).GetProperty("Name")); Expression right = Expression.Constant("心情"); Expression filter = Expression.Equal(left, right); var result = db.ExpresstionClass.Where(Expression.Lambda<Func<ExpressionClassModel, bool>>(filter, param));
生成的sql语句:SELECT [Extent1].[ID] AS [ID], [Extent1].[Name] AS [Name], [Extent1].[Order] AS [Order]FROM [dbo].[Examda_Expression_Class] AS [Extent1] WHERE N'心情' = [Extent1].[Name]
怎么把条件N'心情'参数化呢@p_linq_0 = [Extent1].[Name]
而不是拼接的方式
不知道,等待高手