How can I load class's part using linq to sql without anonymous class or additional class?
- by ais
class Test {
int Id{get;set;}
string Name {get;set;}
string Description {get;set;}
}
//1)ok
context.Tests.Select(t => new {t.Id, t.Name}).ToList().Select(t => new Test{Id = t.Id,
Name = t.Name});
//2)ok
class TestPart{
int Id{get;set;}
string Name {get;set;}
}
context.Tests.Select(t => new TestPart{Id = t.Id,
Name = t.Name}).ToList().Select(t => new Test{Id = t.Id,
Name = t.Name});
//3)error Explicit construction of entity type 'Test' in query is not allowed.
context.Tests.Select(t => new Test{Id = t.Id,
Name = t.Name}).ToList();
Is there any way to use third variant?