i have a code like this.
Context:
public class TestContext : System.Data.Entity.DbContext
{
public TestContext()
: base("name=TestContext")
{
}
public System.Data.Entity.DbSet<TestClass> TestClass { get; set; }
public System.Data.Entity.DbSet<TestSubClass> TestSubClass { get; set; }
}
TestClass:
public class TestClass
{
[Key]
public Guid Id { get; set; }
public string Name { get; set; }
}
TestSubClass:
public class TestSubClass
{
[Key]
public Guid Id { get; set; }
public int Status { get; set; }
[Column("Test")]
public Guid? TestId { get; set; }
[ForeignKey("TestId")]
public virtual TestClass Test { get; set; }
}
GetEverything: / Problem
public static IQueryable<TestClass> GetEverything(bool onlyVisible = false)
{
IQueryable<TestClass> query;
using(var context = new TestContext())
{
query = from test in context.TestClass
select test;
if (onlyVisible)
{
query
.Join(context.TestSubClass, test => test.Id, testSub => testSub.TestId, (test, testSub) => new { TestClass = test, TestSubClass = testSub })
.Where(test => test.TestSubClass.Status == 1)
;
/*
* I want to add something like this:
*
query +=
join testSub in context.TestSubClass on test.Id equals testSub.TestId
where testSub.Status == 1
;
*/
}
}
return query;
}
And if you look at the comment you know what i want.
The problem is that i dont know how to combine multiple of these things performance.
Or how I can combine that better?
I have a basic query string which would be extended by additional things.
But i think these additional things are not pretty readable and understable for third persons...
TestClass- Moment, i edit something.IQueryablebefore enumerating it.IQueryable.Includeis the method for getting related entities in the same query.query = query.Where(test => test.TestSubClass.Any(t => t.TestId == test.Id && t.Status == 1));If i addpublic virtual ICollection<TestSubClass> TestSubClass { get; set; }toTestClass