首页 新闻 会员 周边 捐助

LINQ to SQL语句之动态查询条件如何参数化

0
悬赏园豆:50 [已关闭问题] 关闭于 2013-05-23 13:55
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]

而不是拼接的方式

sky_net的主页 sky_net | 初学一级 | 园豆:10
提问于:2013-04-26 11:04
< >
分享
所有回答(1)
0

不知道,等待高手

不负春光,努力生长 | 园豆:1382 (小虾三级) | 2013-04-26 22:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册