0
|
1 using System;
|
|
2 using System.Linq;
|
|
3 using System.Linq.Expressions;
|
|
4
|
|
5 using NUnit.Framework;
|
|
6
|
|
7 using BLToolkit.Linq;
|
|
8
|
|
9 namespace Data.Linq
|
|
10 {
|
|
11 using Model;
|
|
12
|
|
13 [TestFixture]
|
|
14 public class GenerateTest : TestBase
|
|
15 {
|
|
16 [Test]
|
|
17 public void GeneratePredicate()
|
|
18 {
|
|
19 Expression<Func<Person,bool>> a = x => x.FirstName == "John";
|
|
20 Expression<Func<Person,bool>> b = x => x.LastName == "Pupkin";
|
|
21
|
|
22 var bBody = b.Body.Convert(e => e == b.Parameters[0] ? a.Parameters[0] : e);
|
|
23 var predicate = Expression.Lambda<Func<Person,bool>>(Expression.AndAlso(a.Body, bBody), a.Parameters[0]);
|
|
24
|
|
25 using (var db = new TestDbManager())
|
|
26 {
|
|
27 var q = db.Person.Where(predicate);
|
|
28 var p = q.First();
|
|
29 }
|
|
30 }
|
|
31 }
|
|
32 }
|