/// <summary> /// Counts all the entities of the specified type matching the specified values. /// </summary> /// <param name="type">The type of entity to retrieve.</param> /// <param name="parameters">The parameters to query with.</param> /// <returns>The total number of entities counted.</returns> public override int CountEntities <T>(string propertyName, object propertyValue) { int total = 0; Type type = typeof(T); //using (LogGroup logGroup = LogGroup.StartDebug("Counting the entities of the specified type with a property matching the provided name and value.")) //{ // LogWriter.Debug("Type: " + type.ToString()); // LogWriter.Debug("Property name: " + propertyName); // LogWriter.Debug("Property value: " + (propertyValue == null ? "[null]" : propertyValue.ToString())); Db4oDataStore store = ((Db4oDataStore)GetDataStore(type)); if (store != null) { if (store.ObjectContainer != null) { IQuery query = store.ObjectContainer.Query(); query.Constrain(typeof(T)); query.Descend(EntitiesUtilities.GetFieldName(typeof(T), propertyName)).Constrain(propertyValue); IObjectSet os = query.Execute(); total = os.Count; } } //LogWriter.Debug("Results: " + results.Count.ToString()); //} return(total); }
public void Test_GetFieldName() { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); string fieldName = EntitiesUtilities.GetFieldName(article.GetType(), "Title"); Assert.AreEqual("title", fieldName, "Incorrect field name returned."); }
/// <summary> /// Retrieves all the entities of the specified type with the specified property matching the provided value. /// </summary> /// <param name="propertyName">The name of the property to check the value of.</param> /// <param name="propertyValue">The value to check for on the specified property.</param> /// <returns>The entities that match the provided parameters.</returns> public override IEntity[] GetEntities(Type type, string propertyName, object propertyValue) { Collection <IEntity> results = new Collection <IEntity>(); using (LogGroup logGroup = LogGroup.StartDebug("Retrieving the entities of the specified type with a property matching the provided name and value.")) { if (type == null) { throw new ArgumentNullException("type"); } if (propertyName == null || propertyName == String.Empty) { throw new ArgumentException("A property name must be provided.", "propertyName"); } if (!EntityState.IsType(type)) { throw new ArgumentException("The provided '" + type.Name + "' type is not registered as a valid entity type."); } LogWriter.Debug("Type: " + type.ToString()); LogWriter.Debug("Property name: " + propertyName); LogWriter.Debug("Property value: " + (propertyValue == null ? "[null]" : propertyValue.ToString())); Db4oDataStore store = ((Db4oDataStore)GetDataStore(type)); if (store != null) { if (store.ObjectContainer != null) { IQuery query = store.ObjectContainer.Query(); query.Constrain(type); query.Descend(EntitiesUtilities.GetFieldName(type, propertyName)) .Constrain(propertyValue); IObjectSet os = query.Execute(); while (os.HasNext()) { results.Add((IEntity)os.Next()); } } } LogWriter.Debug("Entities #: " + results.Count.ToString()); } return(Release(results.ToArray())); }