public static void InitializeTableData <TEntity>(
                ITable <TEntity> table,
                IEnumerable <object> entities)

                where TEntity : class
            {
                IExtendedTable <TEntity> exTable = table as IExtendedTable <TEntity>;

                if (exTable != null)
                {
                    exTable.Initialize(entities.Cast <TEntity>());
                }
            }
示例#2
0
        public void SetIdentity <TEntity>(int?seed, int?increment)
        {
            if (container.database == null)
            {
                // BD not create...
                throw new Exception("NEED TEXT!");
            }

            var tables = ((List <ITable>)container.GetAllTables());

            Dictionary <string, DbTableInfo> listDbTableInfo = new Dictionary <string, DbTableInfo>();

            foreach (var tableToFindDbTableInfo in tables)
            {
                // copy past  public DbTableInfo GetTableInfo(string schema, string name) from EffortConnection
                {
                    var _TableInfo = tableToFindDbTableInfo.GetType().GetProperty("TableInfo",
                                                                                  BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);

                    if (_TableInfo != null)
                    {
                        var TableInfo = (DbTableInfo)_TableInfo.GetValue(tableToFindDbTableInfo, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, null, null);
                        if (TableInfo != null && TableInfo.EntitySet != null && TableInfo.EntitySet.Name != null)
                        {
                            listDbTableInfo.Add(TableInfo.EntitySet.Name, TableInfo);
                        }
                    }
                }
            }

            DbTableInfo    dbTableInfo = null;
            IExtendedTable table       = null;

            if (listDbTableInfo.TryGetValue((typeof(TEntity).Name), out dbTableInfo))
            {
                table = tables.Where(x => x.EntityType.FullName == dbTableInfo.EntityType.FullName).FirstOrDefault() as IExtendedTable;
            }

            if (table != null)
            {
                table.SetIdentity(seed, increment);
            }
            else
            {
                throw new Exception("Invalid table name");
            }
        }
示例#3
0
        public void ClearTables()
        {
            var specialTables = new List <string>()
            {
                MigrationHistoryTable
            };

            this.SetRelations(false);

            foreach (TableName name in this.container.TableNames)
            {
                if (specialTables.Contains(name.Name))
                {
                    continue;
                }

                IExtendedTable table = (IExtendedTable)this.container.GetTable(name);
                table.Clear();
            }

            this.SetRelations(true);
        }