public ColumnInfo(ColumnSchema column, MemberOption memberOption, SqlOption sqlOption, IDbVendor dbVendor) { if (column == null) throw new ArgumentNullException("column"); if (memberOption == null) throw new ArgumentNullException("memberOption"); if (dbVendor == null) throw new ArgumentNullException("dbVendor"); //Assign parameters to member variables. m_Column = column; m_MemberOption = memberOption; m_SqlOption = sqlOption; m_DbVendor = dbVendor; m_ClrType = DbVendor.GetClrType(column, MemberOption.UseNullable); m_ClrPrimitiveType = Nullable.GetUnderlyingType(m_ClrType); m_ClrPrimitiveType = (m_ClrPrimitiveType != null) ? m_ClrPrimitiveType : m_ClrType; m_IsClrNullable = Nullable.GetUnderlyingType(m_ClrType) != null; //m_ClrTypeDecl = GetClrTypeDecl(m_ClrType); m_ClrTypeDecl = CSHelper.CSharpType(m_Column); m_IsLob = DbVendor.IsLob(Column); m_PropName = GetPropName(Column, MemberOption); m_VarName = GetVarName(PropName, MemberOption); m_ClrParamName = CSHelper.GetCamelCase(PropName); m_ClrParamDecl = ClrTypeDecl + " " + ClrParamName; m_InitialValueDecl = m_IsClrNullable ? " = null" : String.Empty; m_PropAccessDecl = CSHelper.GetMemberAccessName(MemberOption.PropAccess); m_VarAccessDecl = CSHelper.GetMemberAccessName(MemberOption.VarAccess); m_ProviderDbType = DbVendor.GetProviderDbType(Column); m_ProviderDbTypeName = DbVendor.GetProviderDbTypeName(m_ProviderDbType); m_IsExpilicit = DbVendor.IsExplicit(Column); m_ResultColumnName = Column.Name; m_SqlColumnName = DbVendor.QuotedStr(Column.Name); m_SqlQualifiedColumnName = DbVendor.QuotedStr(column.Table.Name) + "." + m_SqlColumnName; m_SqlInlineParameterMap = GetSqlInlineParameterMap(PropName, ClrTypeDecl, ProviderDbTypeName, IsExpilicit, SqlOption); m_SqlParameterClass = m_ClrPrimitiveType.Name; }
/// <summary>Creates an instance.</summary> public TableBuilder(TableSchema sourceTable, ITableBuilderOption builderOption) { if (sourceTable == null) throw new ArgumentNullException("sourceTable"); if (builderOption == null) throw new ArgumentNullException("builderOption"); m_SourceTable = sourceTable; m_BuilderOption = builderOption; m_DbVendor = DbVendorProvider.GetVendor(m_BuilderOption.SqlOption.VendorId); m_TableName = DbVendor.QuotedStr(SourceTable.Name); m_QualifiedTableName = DbVendor.QuotedStr(SourceTable.Owner) + "." + TableName; m_EntityNamespace = EntityOption.Namespace; m_EntityName = GetEntityName(SourceTable.Name, EntityOption); m_EntityFullName = CSHelper.GetQualifiedName(EntityName, EntityNamespace); m_EntityQualifiedName = CSHelper.GetAssemblyQualifiedName(EntityFullName, EntityOption.Assembly); m_EntityPartialDecl = EntityOption.IsPartial ? "partial " : String.Empty; m_EntityBaseDecl = String.IsNullOrEmpty(EntityOption.BaseType) ? String.Empty : " : " + EntityOption.BaseType; m_DaoIntfNamespace = DaoIntfOption.Namespace; m_DaoIntfName = String.Format(DaoIntfOption.NameFmt, EntityName); m_DaoIntfFullName = CSHelper.GetQualifiedName(DaoIntfName, DaoIntfNamespace); m_DaoIntfQualifiedName = CSHelper.GetAssemblyQualifiedName(DaoIntfFullName, DaoIntfOption.Assembly); m_DaoIntfPartialDecl = DaoIntfOption.IsPartial ? "partial " : String.Empty; m_DaoIntfBaseDecl = String.IsNullOrEmpty(DaoIntfOption.BaseType) ? String.Empty : " : " + DaoIntfOption.BaseType; m_DaoImplNamespace = DaoImplOption.Namespace; m_DaoImplName = String.Format(DaoImplOption.NameFmt, EntityName); m_DaoImplFullName = CSHelper.GetQualifiedName(DaoImplName, DaoImplNamespace); m_DaoImplQualifiedName = CSHelper.GetAssemblyQualifiedName(DaoImplQualifiedName, DaoImplOption.Assembly); m_DaoImplPartialDecl = DaoImplOption.IsPartial ? "partial " : String.Empty; m_DaoImplBaseDecl = " : " + DaoImplOption.BaseType + (String.IsNullOrEmpty(DaoImplOption.BaseType) ? String.Empty : ", ") + m_DaoIntfName; m_SqlMapper = DaoImplOption.SqlMapperFmt; int columnCount = SourceTable.Columns.Count; bool isSingleColumnPk = SourceTable.PrimaryKey.MemberColumns.Count == 1; //If the table has a single-column primary key. //Initialize column lists List<ColumnInfo> columns = new List<ColumnInfo>(columnCount); List<ColumnInfo> pkColumns = new List<ColumnInfo>(SourceTable.PrimaryKey.MemberColumns.Count); List<ColumnInfo> nonPkColumns = new List<ColumnInfo>(columnCount); List<ColumnInfo> finderColumns = new List<ColumnInfo>(columnCount); List<ColumnInfo> lobColumns = new List<ColumnInfo>(columnCount); List<ColumnInfo> nonLobColumns = new List<ColumnInfo>(columnCount); foreach (ColumnSchema c in SourceTable.Columns) { ColumnInfo cb = new ColumnInfo(c, MemberOption, DbVendor); columns.Add(cb); if (c.IsPrimaryKeyMember) { pkColumns.Add(cb); } else { nonPkColumns.Add(cb); } if (cb.IsLob) lobColumns.Add(cb); else nonLobColumns.Add(cb); //Determinates if the column will be used in FindByXXX. if (c.IsPrimaryKeyMember && isSingleColumnPk) continue; if (cb.IsLob) continue; finderColumns.Add(cb); } m_Columns = columns.AsReadOnly(); m_PkColumns = pkColumns.AsReadOnly(); m_NonPkColumns = nonPkColumns.AsReadOnly(); m_FinderColumns = finderColumns.AsReadOnly(); m_LobColumns = lobColumns.AsReadOnly(); m_NonLobColumns = nonLobColumns.AsReadOnly(); m_HasLob = lobColumns.Count > 0; m_IdBase = GetIdBase(m_EntityName, m_EntityNamespace, SqlOption); }