コード例 #1
0
        public void CreateColumn(DatabaseColumnInfo column)
        {
            if (column == null)
                throw new ArgumentNullException("column");

            DataContext.DatabaseColumnInfoes.Add(column);
            DataContext.SaveChanges();
        }
コード例 #2
0
        public void DeleteColumn(DatabaseColumnInfo column)
        {
            if (column == null)
                throw new ArgumentNullException("column");

            DataContext.Entry<DatabaseColumnInfo>(column).State = System.Data.EntityState.Deleted;
            DataContext.SaveChanges();
        }
コード例 #3
0
        public void InitialTable(int tableId, string connectionString)
        {
            if (string.IsNullOrEmpty(connectionString))
                throw new ArgumentNullException("connectionString");

            var tableinfo = DataContext.DatabaseTableInfoes.Where(i => i.ID == tableId).FirstOrDefault();
            if (tableinfo == null)
                throw new ArgumentNullException("找不到指定的表信息。");

            //get columns info
            var columninfos = DBHelper.GetAllColumnInformation(connectionString, tableinfo.Name);
            var columns = DataContext.DatabaseColumnInfoes.Where(i => i.DatabaseTableInfoID == tableId);

            foreach (var item in columninfos)
            {
                if (columns.Count(i => i.Name == item.Name) == 0)
                {
                    DatabaseColumnInfo column = new DatabaseColumnInfo();
                    column.CanNull = item.CanNull;
                    column.ChineseName = item.Remark;
                    column.CreationTime = DateTime.Now;
                    column.DatabaseTableInfoID = tableId;
                    column.DataType = item.DataType;
                    column.DefaultValue = item.DefaultValue;
                    column.IsIdentity = item.IsIdentity;
                    column.IsPrimaryKey = item.IsPK;
                    column.LastUpdateTime = DateTime.Now;
                    column.Length = item.Length;
                    column.Name = item.Name;

                    this.CreateColumn(column);
                }
            }
        }