public Guid Create( BusinessEntity entity ) { Guid id = Guid.NewGuid(); string name = entity.GetType().Name; if( data.ContainsKey( name ) == false ) { data.Add( name, new BusinessEntityCollection() ); } if( name == "DynamicEntity" ) { DynamicEntity de = ( DynamicEntity )entity; name = de.Name; de.Properties.Add( new KeyProperty( de.Name + "id", new Key( id ) ) ); } else { entity.GetType().GetProperty( name + "id" ).SetValue( entity, new Key( id ), null ); } if( !data.ContainsKey( name ) ) { data[ name ] = new BusinessEntityCollection(); } data[ name ].BusinessEntities.Add( entity ); if( m_persist ) { PersistToDisk( m_filename ); } return id; }
public BusinessEntityCollection RetrieveMultiple( Microsoft.Crm.Sdk.Query.QueryBase query ) { QueryExpression queryExpression = ( QueryExpression )query; BusinessEntityCollection retval = new BusinessEntityCollection(); if( data.ContainsKey( query.EntityName ) ) { foreach( BusinessEntity entity in data[ query.EntityName ].BusinessEntities ) { if( true == EvaluateFilters( queryExpression.Criteria, entity ) && true == EvaluateLinks( queryExpression.LinkEntities, entity ) ) { retval.BusinessEntities.Add( entity ); } } } return retval; }