How can I load class's part using linq to sql without anonymous class or additional class?

Posted by ais on Stack Overflow See other posts from Stack Overflow or by ais
Published on 2010-06-10T10:23:33Z Indexed on 2010/06/10 10:42 UTC
Read the original article Hit count: 281

Filed under:
|
|
|
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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about LINQ