How can I move data from domain to business entity using 'select new' LINQ query [Resolved]

Posted by Kasani007 under LINQ on 5/18/2016 | Points: 10 | Views : 586 | Status : [Member] | Replies : 1
Linq query by using select new

public class Parent
{
public ParentId{get;set;}
public ParentName{get;set;}
public List<Child> childs{get;set;}
}

public class Child
{
public ChildId{get;set;}
public ChildName{get;set;}
}


How can i move data from Domain Entity To Business Entity using Linq

List<Parent> parents=GetALLParentData();
List<ParentBE> parentBE=from p in parents
select new ParentBE
{
ParentId=p.ParentId,
ParentName=p.ParentName,
ChildBE.ChildId=p.Child.ChildId,
ChildBE.ChildName=p.Child.ChildName
}


long Child.ChildId
Error:
An object reference is required for the non-static field, method, or property 'Child.ChildId.get'

string Child.ChildName
Error:
An object reference is required for the non-static field, method, or property 'Child.ChildName.get'

How can move the data of List Of child domain entity to business entity along with parent domain entity to business entity using LINQ




Responses

Posted by: Rajnilari2015 on: 7/12/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try

public List<ParentBE> GetRecords()

{
List<Parent> parents=GetALLParentData();
return

(
from p in parents
select new ParentBE
{
ParentId=p.ParentId,
ParentName=p.ParentName,
ChildBE.ChildId=p.Child.ChildId,
ChildBE.ChildName=p.Child.ChildName
}).toList();
}


Hope that helps.

--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response