how to convert system.data.datable to Entitycollection

Posts   
 
    
weezer
User
Posts: 42
Joined: 24-Apr-2012
# Posted on: 04-Jul-2012 10:47:08   

I receiving the error since that i am trying to convert system.data.datable to entity collection. Please advise how i should implement it? thank you

public EntityCollection<ParticipationEntity> GetProgramInstanceParticipationByInstancesId(int programInstanceId) { EntityCollection<ParticipationEntity> pEC = new EntityCollection<ParticipationEntity>(); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.AddWithAnd(ParticipationFields.ProgramInstanceId == programInstanceId); IPrefetchPath2 pfPath = new PrefetchPath2(EntityType.ParticipationEntity); pfPath.Add(ParticipationEntity.PrefetchPathStudentEnrolment);

        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntityCollection(pEC, filter, pfPath);
        }

        EntityService es = new EntityService();
        DataTable dt = new DataTable();
        dt = es.CollectionToDataTable<ParticipationEntity>(pEC, "");

        dt.Columns.Add("StudentName");

        int i = 0;

        foreach (DataRow r in dt.Rows)
        {
            r["StudentName"] = pEC.Items[i].StudentEnrolment.Surname + ", " + pEC.Items[i].StudentEnrolment.GivenName;
            i++;
        }

        return dt;
    }
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jul-2012 19:00:12   

Please look into Projection

weezer
User
Posts: 42
Joined: 24-Apr-2012
# Posted on: 05-Jul-2012 05:23:40   

Thank you