public DbEntryDesignerDataSourceView(DbEntryDataSourceDesigner owner)
     : base(owner, "MainView")
 {
     _dataSource = (DataSourceControl)owner.Component;
     _modelType = _dataSource.GetType().BaseType.GetGenericArguments()[0];
     _info = ObjectInfoFactory.Instance.GetInstance(_modelType);
 }
示例#2
0
 private List<Type> GetCreateTables(ObjectInfo info)
 {
     if (info.From.PartOf != null)
     {
         return new List<Type> { info.From.PartOf };
     }
     if (info.From.JoinClauseList != null)
     {
         var jar = new Dictionary<Type, int>();
         foreach (JoinClause jc in info.From.JoinClauseList)
         {
             if (jc.Type1 != null)
             {
                 jar[jc.Type1] = 1;
             }
             if (jc.Type2 != null)
             {
                 jar[jc.Type2] = 1;
             }
         }
         if (jar.Count > 0)
         {
             return new List<Type>(jar.Keys);
         }
     }
     return new List<Type> { info.HandleType };
 }
示例#3
0
 public static AutoSchemeFixer CreateInstance(DataProvider provider, ObjectInfo info)
 {
     switch(provider.Driver.AutoScheme)
     {
         case AutoScheme.None:
             return new AutoSchemeFixer();
         case AutoScheme.CreateTable:
             return new AutoSchemeFixerCreateTable(provider, info);
         case AutoScheme.AddColumns:
             return new AutoSchemeFixerAddColumns(provider, info);
         case AutoScheme.RemoveColumns:
             return new AutoSchemeFixerRemoveColumns(provider, info);
         default:
             throw new DataException("Application Error");
     }
 }
示例#4
0
 public override SqlStatement GetAddDescriptionSql(ObjectInfo info)
 {
     const string template = "EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{2}' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'{0}', @level2type=N'COLUMN', @level2name=N'{1}';\n";
     var sb = new StringBuilder();
     string table = info.From.MainTableName;
     foreach (var field in info.SimpleMembers)
     {
         if (!field.Description.IsNullOrEmpty())
         {
             sb.Append(string.Format(template, table, field.Name, field.Description.Replace("'", "''")));
         }
     }
     if (sb.Length > 0)
     {
         return new SqlStatement(sb.ToString());
     }
     return null;
 }
 public DbEntryDataSourceViewSchema(ObjectInfo oi)
 {
     this._oi = oi;
 }
示例#6
0
 internal CachedModelOperator(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler)
     : base(info, composer, provider, handler)
 {
 }
示例#7
0
 public AutoSchemeFixerCreateTable(DataProvider provider, ObjectInfo info)
 {
     this.Provider = provider;
     _createTables = GetCreateTables(info);
 }
示例#8
0
 public AutoSchemeFixerRemoveColumns(DataProvider provider, ObjectInfo info) : base(provider, info)
 {
 }
示例#9
0
 public virtual SqlStatement GetAddDescriptionSql(ObjectInfo info)
 {
     return null;
 }
示例#10
0
 protected virtual object ExecuteInsertIntKey(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider)
 {
     SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog);
     sql.SqlCommandText = AddIdentitySelectToInsert(sql.SqlCommandText);
     return provider.ExecuteScalar(sql);
 }
示例#11
0
 public virtual object ExecuteInsert(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider)
 {
     if (info.HasOnePrimaryKey && info.KeyMembers[0].MemberType == typeof(Guid))
     {
         if(info.KeyMembers[0].Is.DbGenerateGuid)
         {
             Guid key = Util.NewGuid();
             sb.Values[0].Value = key;
         }
         SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog);
         provider.ExecuteNonQuery(sql);
         return sb.Values[0].Value;
     }
     return ExecuteInsertIntKey(sb, info, provider);
 }
示例#12
0
 private static string GetColumnName(ObjectInfo oi, string name)
 {
     foreach(MemberHandler mh in oi.Members)
     {
         if(mh.MemberInfo.Name == name)
         {
             return mh.Name;
         }
     }
     throw new DataException("Can not find field [" + name + "] on [" + oi.HandleType.Name + "]");
 }
示例#13
0
 private static void SetManyToManyFrom(ObjectInfo oi, string unmappedMainTableName, IEnumerable<MemberHandler> fields)
 {
     foreach (MemberHandler member in fields)
     {
         if (member.Is.HasAndBelongsToMany)
         {
             var modelType = member.MemberType.GetGenericArguments()[0];
             var fromClause = GetObjectFromClause(modelType);
             var mainOriginTableName = fromClause.MainModelName;
             var name = GetCrossTableName(member, unmappedMainTableName, mainOriginTableName);
             var fkMainOriginTableName = mainOriginTableName + "_Id";
             var from = new FromClause(new[] { new JoinClause(name, fkMainOriginTableName, fromClause.MainTableName, "Id", CompareOpration.Equal, JoinMode.Inner) });
             var handleType = member.MemberType.GetGenericArguments()[0];
             oi.CrossTables[handleType] = new CrossTable(handleType, from, name,
                 oi.From.MainTableName, unmappedMainTableName + "_Id", fromClause.MainTableName, fkMainOriginTableName);
         }
     }
 }