Linq Birleşimine katıl seçeneğinde birden çok tabloya yayılan yüklemeleri dinamik olarak oluşturmak istiyorum.PredicateBuilder, birden çok tabloya yayılan yüklemler oluşturabilir mi?
değiştirin:
public class Foo
{
public int FooId; // PK
public string Name;
}
public class Bar
{
public int BarId; // PK
public string Description;
public int FooId; // FK to Foo.PK
}
void Test()
{
IQueryable<Foo> fooQuery = null; // Stubbed out
IQueryable<Bar> barQuery = null; // Stubbed out
IQueryable<Foo> query =
from foo in fooQuery
join bar in barQuery on foo.FooId equals bar.FooId
where ((bar.Description == "barstring") || (foo.Name == "fooname"))
select foo;
}
gibi bir şey ile:
void Test(bool searchName, bool searchDescription)
{
IQueryable<Foo> fooQuery = null; // Stubbed out
IQueryable<Bar> barQuery = null; // Stubbed out
IQueryable<Foo> query =
from foo in fooQuery
join bar in barQuery on foo.FooId equals bar.FooId
select foo;
// OR THIS
var query =
from foo in fooQuery
join bar in barQuery on foo.FooId equals bar.FooId
select new {foo, bar};
var predicate = PredicateBuilder.False<Foo>();
if (searchName)
{
predicate = predicate.Or(foo => foo.Name == "fooname");
}
if (searchDescription)
{
// Cannot compile
predicate = predicate.Or(bar => bar.Description == "barstring");
}
// Cannot compile
query = query.Where(predicate);
}
aşağıdaki kod parçacığını, ben şu kodda 'nerede' deyimi yerine PredicateBuilder veya benzer yapısını kullanmak istiyorum
Bu sorunun üstesinden gelmek için herhangi bir düşünce, fikir, strateji? senin yüklem yarım Foo hareket eden, diğer yarısı bir Bar açıksa -
sayesinde
EulerOperator