/* private XPMemberInfo GetCollectionProperty(string name) { XPMemberInfo info1 = ClassInfo.GetMember(name); if (info1 == null) { throw new PropertyMissingException(ClassInfo.FullName, name); } return info1; } */ // /// <summary> // /// Stores all XPCollections marked with NoSaveAggregation // /// </summary> // private Hashtable CollectionsNoSaveAggregation // { // get // { // if (collectionsNoSaveAggregation == null) // collectionsNoSaveAggregation = new Hashtable(); // // return collectionsNoSaveAggregation; // } // } public static XPCollection CreatePropertyCollectionNoSaveAggregation(DBObject owner, XPMemberInfo collectionProperty) { if (collectionProperty.IsManyToMany) // return new XPManyToManyNoSaveAggregation(owner, collectionProperty); throw new NotImplementedException("IsManyToMany on CreatePropertyCollectionNoSaveAggregation on " + owner.GetType().FullName); return new XPCollection(owner.Session, owner, collectionProperty); // return new XPOneToManyCollectionNoSaveAggregation(owner, collectionProperty.Name); // AssociationAttribute attribute = (AssociationAttribute) collectionProperty.GetAttributeInfo(typeof(AssociationAttribute)); // // Type typeOfCollection = FindTypeOfCollection(attribute); //// Type[] types = new Type[] {owner.GetType()}; //// Type builderType = GetBuilderType(typeOfCollection); //// MethodInfo methodInfo = builderType.GetMethod("GetAll", types); //// if (methodInfo == null) //// throw new MethodNotFoundException(builderType, "GetAll", types); // XPOneToManyCollectionNoSaveAggregation xpOneToManyCollectionNoSaveAggregation = new XPOneToManyCollectionNoSaveAggregation(owner, collectionProperty.Name); // PropertyInfo[] propertyInfos = ReflectorHelper.GetDecoratedProperties(typeOfCollection, typeof(AssociationAttribute)); // string propertyName = null; // foreach (PropertyInfo info in propertyInfos) // if (((AssociationAttribute) info.GetCustomAttributes(typeof (AssociationAttribute), true)[0]).Name == // attribute.Name) // propertyName = info.Name; // // DBCollection dbCollection = new DBCollection(owner.Session,typeOfCollection,new BinaryOperator(propertyName,owner)); // foreach (DBObject dbObject in dbCollection) // { // if (xpOneToManyCollectionNoSaveAggregation.Lookup(dbObject.ClassInfo.KeyProperty.GetValue(dbObject)) ==null) // xpOneToManyCollectionNoSaveAggregation.Add(dbObject); // } // // return xpOneToManyCollectionNoSaveAggregation; }
public static string GetFileData(Session session, DBObject document, string propertyName) { #region getField name XPMemberInfo member = document.ClassInfo.GetMember(propertyName); if (member.HasAttribute(typeof (PersistentAttribute))) { var attribute = (PersistentAttribute) member.GetAttributeInfo(typeof (PersistentAttribute)); propertyName = attribute.MapTo; } #endregion #region getTableName string tableName = document.GetType().Name; object[] attributes = document.GetType().GetCustomAttributes(typeof (MapToAttribute), true); if (attributes.Length > 0) tableName = ((MapToAttribute) attributes[0]).MappingName; #endregion IDbCommand command = session.Connection.CreateCommand(); command.CommandText = "SELECT " + propertyName + " FROM " + tableName + " WHERE " + document.ClassInfo.KeyProperty.Name + "=" + document.ClassInfo.KeyProperty.GetValue(document); object reader = command.ExecuteScalar(); var fileData = reader as string; command.Dispose(); // session.Connection.Close(); return fileData; }