Esempio n. 1
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");
            }
        }