The Fields.State value after projecting on to a collection.

Posts   
 
    
siegemos
User
Posts: 47
Joined: 25-Jun-2007
# Posted on: 24-Jul-2009 17:45:00   

Hi all,

I'm trying to project the results of a stored procedure on to an entity collection. It all works fine, the only problem is that the fields.state property is set to new. I need it to be 'fetched' as this gets checked during a separate process. Is there an easy way of setting this field during the projection process? Or do I have to loop around the entire collection again?

Current code



ProductCollection products = new ProductCollection(new ExtendedProductFactory());

using (IRetrievalQuery query = RetrievalProcedures.GetFuzzyProductSearchCallAsQuery(keyword))
{
    TypedListDAO dao = new TypedListDAO();
    using (IDataReader reader = dao.GetAsDataReader(null, query, CommandBehavior.CloseConnection))
    {
    List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
    valueProjectors.Add(new DataValueProjector(ProductFieldIndex.Id.ToString(), 2, typeof(int)));
    valueProjectors.Add(new DataValueProjector(ProductFieldIndex.Code.ToString(), 3, typeof(string)));
    valueProjectors.Add(new DataValueProjector(ProductFieldIndex.Name.ToString(), 4, typeof(string)));
    etc etc...

    DataProjectorToIEntityCollection projector = new DataProjectorToIEntityCollection(products);

    dao.GetAsProjection(valueProjectors, projector, reader);
    reader.Close();
    }
}
return products;



Thanks in advance,

Chris Moseley.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Jul-2009 20:15:29   

Hi Moseley,

Quoted from here:

They're not marked as fetched. If you want that, please create your own projector class. Please have a look at ORMSupportClasses\Projection\DataProjectorToEntityCollection.cs (contains 2 classes, one for selfservicing and one for adapter). It's really straightforward, so making a copy of that code and alter it to your liking (e.g. set the IsNew flag to false, the IsDirty flag to false and the entity.Fields.State enum to Fetched) is easy to add. To perform the projection, you then simply use your class as projector instead of the default one.

David Elizondo | LLBLGen Support Team