private int FillEntity(Type entityType, string oledbConnectionString, IObjectContainer db4OContainer, int topRows) { var tableAttrib = entityType.GetAttribute <TableInformationAttribute>(); if (tableAttrib == null) { return(0); } var properties = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(prop => prop.GetAttribute <ColumnInformationAttribute>() != null) .ToList(); if (properties.Count == 0) { return(0); } var columnList = properties.Select( prop => prop.GetAttribute <ColumnInformationAttribute>().ColumnName).ToList(); var select = MigratorUtilities.GetSelectProvider(oledbConnectionString).GetSqlQuery(tableAttrib.TableName, columnList, topRows); return(MigratorUtilities.AddOledbRowsToEntity(entityType, select, properties, oledbConnectionString, db4OContainer)); }
private void FillRelationsOfEntity(Type entityType, IObjectContainer db4OContainer, int poolCount) { var relations = MigratorUtilities.GetRelationsOfEntity(entityType); if (relations == null || relations.Count == 0) { return; } var properties = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); var fields = entityType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); var entityQuery = db4OContainer.Query(); entityQuery.Constrain(entityType); var entityList = entityQuery.Execute().ToList <object>(db4OContainer, 1); var entityListCount = entityList == null ? 0 : entityList.Count; if (entityListCount == 0) { return; } var entityTempCount = 0; var blder = new StringBuilder(); foreach (var entity in entityList) { //foreach (var relation in relations) //{ // var propertyAttrib = relation.Key; // var relAttrib = relation.Value; // if (!relAttrib.IsEntityParent) // { // #region FIND AND SET PARENT PROPERTY // var parentQuery = db4OContainer.Query(); // parentQuery.Constrain(propertyAttrib.PropertyType); // var colsCount = relAttrib.ParentColumnNames.Count(); // for (var i = 0; i < colsCount; i++) // { // var propertyName = relAttrib.PropertyNames[i]; // var foreigFieldName = relAttrib.ForeignFieldNames[i]; // var propertyInfo = properties.Single(prop => prop.Name.Equals(propertyName)); // var propertyValue = propertyInfo.GetValue(entity, null); // parentQuery.Descend(foreigFieldName).Constrain(propertyValue).Equal(); // } // var parent = parentQuery.Execute().ToList<object>(db4OContainer, 1).SingleOrDefault(); // if (parent == null) // continue; // propertyAttrib.SetValue(entity, parent, null); // #endregion // } // else // { // #region FIND CHILD PROPERTIES // var collectionType = propertyAttrib.PropertyType.GetGenericTypeDefinition(); // var collectionField = fields.Single(fl => fl.Name.Equals(relAttrib.PrivateCollectionFieldName)); // var childType = propertyAttrib.PropertyType.GetGenericArguments()[0]; // var childQuery = db4OContainer.Query(); // childQuery.Constrain(childType); // var colsCount = relAttrib.ChildColumnNames.Count(); // for (var i = 0; i < colsCount; i++) // { // var propertyName = relAttrib.PropertyNames[i]; // var foreigFieldName = relAttrib.ForeignFieldNames[i]; // var propertyInfo = properties.Single(prop => prop.Name.Equals(propertyName)); // var propertyValue = propertyInfo.GetValue(entity, null); // childQuery.Descend(foreigFieldName).Constrain(propertyValue).Equal(); // } // var childs = childQuery.Execute().ToList<object>(db4OContainer, 1); // if (childs == null || childs.Count == 0) // continue; // var constructedType = collectionType.MakeGenericType(childType); // var childCollection = Activator.CreateInstance(constructedType); // var addMehod = childCollection.GetType().GetMethod("Add"); // foreach (var child in childs) // addMehod.Invoke(childCollection, new[] { child }); // collectionField.SetValue(entity, childCollection); // #endregion // } //} if (entityType.ToString().Contains("CreditCard")) { try { db4OContainer.Store(entity); db4OContainer.Ext().Purge(entity); db4OContainer.Commit(); } catch (Exception excep) { blder.AppendLine(excep.Message); } } entityTempCount++; //if (entityTempCount == poolCount) //{ // db4OContainer.Commit(); // entityTempCount = 0; //} } //if(entityTempCount > 0) // db4OContainer.Commit(); }