I have a class containing three Methods which are working perfectly :
To fetch the data from table :
public IList<RetriveOperatorAcYo> GetRetriveOperatorListGrid(int Uid) { var persons = (from p in _Context.People join a in _Context.Accounts on p.PersonId equals a.PersonId join b in _Context.BusinessTypes on a.BusinessTypeId equals b.BusinessTypeId join d in _Context.AccountUserRelations on a.AccountId equals d.AccountId where b.Name == AccountBusinessTypes.Operator && a.IsDelete == false && d.Active == true && d.UserId == Uid select p); return MapToRetriveOperatorYoList(persons); }
Use as middle function for separating list to single element :
private IList<RetriveOperatorAcYo> MapToRetriveOperatorYoList(IEnumerable<EntityFramework.Person> persons) { return persons.Select(MapToRetirveOperatorYo).ToList(); }
As a Mapping function to generate result :
private RetriveOperatorAcYo MapToRetirveOperatorYo(EntityFramework.Person person) { var vendorYo = new RetriveOperatorAcYo { Id = person.PersonId, FirstName = person.FirstName, LastName = person.LastName, MobileNumber = person.MobileNumber, LandlineNumber = person.LandlineNumber } return vendorYo; }
Now I want to fetch only particular columns data in my first function.
I searched some techniques and tried this :
var persons = (from p in _Context.People
join a in _Context.Accounts on p.PersonId equals a.PersonId
join b in _Context.BusinessTypes on a.BusinessTypeId equals b.BusinessTypeId
join d in _Context.AccountUserRelations on a.AccountId equals d.AccountId
where b.Name == AccountBusinessTypes.Operator && a.IsDelete == false && d.Active == true && d.UserId == Uid
select new
{
PersonId = p.PersonId,
FirstName = p.FirstName,
LastName = p.LastName,
MobileNumber = p.MobileNumber,
LandlineNumber = p.LandlineNumber
});
But it giving me the error in the second function :
"The entity or complex type cannot be constructed in a LINQ to Entities query."
So is there any solution how to map the data and return the particular mapped class with particular details only.
Thanks for the Help in Advance.