public DbEntryDesignerDataSourceView(DbEntryDataSourceDesigner owner) : base(owner, "MainView") { _dataSource = (DataSourceControl)owner.Component; _modelType = _dataSource.GetType().BaseType.GetGenericArguments()[0]; _info = ObjectInfoFactory.Instance.GetInstance(_modelType); }
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 }; }
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"); } }
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; }
internal CachedModelOperator(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) : base(info, composer, provider, handler) { }
public AutoSchemeFixerCreateTable(DataProvider provider, ObjectInfo info) { this.Provider = provider; _createTables = GetCreateTables(info); }
public AutoSchemeFixerRemoveColumns(DataProvider provider, ObjectInfo info) : base(provider, info) { }
public virtual SqlStatement GetAddDescriptionSql(ObjectInfo info) { return null; }
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); }
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); }
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 + "]"); }
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); } } }