Remotion.Linq.SqlBackend.UnitTests.MappingResolverStub.ResolveSimpleTableInfo C# (CSharp) Метод

ResolveSimpleTableInfo() публичный Метод

public ResolveSimpleTableInfo ( IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator ) : SqlEntityDefinitionExpression
tableInfo IResolvedTableInfo
generator UniqueIdentifierGenerator
Результат Remotion.Linq.SqlBackend.SqlStatementModel.Resolved.SqlEntityDefinitionExpression
    public virtual SqlEntityDefinitionExpression ResolveSimpleTableInfo (
        IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator)
    {
      Type type = tableInfo.ItemType;
      if (type == typeof (Cook))
      {
        return new SqlEntityDefinitionExpression (
            tableInfo.ItemType,
            tableInfo.TableAlias, null,
            e => e.GetColumn (typeof (int), "ID", true),
            new[]
            {
                CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
                CreateColumn (typeof (string), tableInfo.TableAlias, "FirstName", false),
                CreateColumn (typeof (string), tableInfo.TableAlias, "Name", false),
                CreateColumn (typeof (bool), tableInfo.TableAlias, "IsStarredCook", false),
                CreateColumn (typeof (bool), tableInfo.TableAlias, "IsFullTimeCook", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "SubstitutedID", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "KitchenID", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "KnifeID", false),
                CreateColumn (typeof (string), tableInfo.TableAlias, "KnifeClassID", false)
            });
      }
      else if (type == typeof (Kitchen))
      {
        return new SqlEntityDefinitionExpression (
            tableInfo.ItemType,
            tableInfo.TableAlias, null,
            e => e.GetColumn (typeof (int), "ID", true),
            new[]
            {
                CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
                CreateColumn (typeof (string), tableInfo.TableAlias, "Name", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "RestaurantID", false),
                CreateColumn (typeof (DateTime?), tableInfo.TableAlias, "LastCleaningDay", false),
                CreateColumn (typeof (bool?), tableInfo.TableAlias, "PassedLastInspection", false),
                CreateColumn (typeof (int?), tableInfo.TableAlias, "LastInspectionScore", false)
            });
      }
      else if (type == typeof (Restaurant))
      {
        return new SqlEntityDefinitionExpression (
            tableInfo.ItemType,
            tableInfo.TableAlias, null,
            e => e.GetColumn (typeof (int), "ID", true),
            new[]
            {
                CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
                CreateColumn (typeof (int), tableInfo.TableAlias, "CompanyID", false)
            });
      }
      else if (type == typeof (Chef))
      {
        return new SqlEntityDefinitionExpression (
            tableInfo.ItemType,
            tableInfo.TableAlias, null,
            e => e.GetColumn (typeof (int), "ID", true),
            new[]
            {
                CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
                CreateColumn (typeof (string), tableInfo.TableAlias, "FirstName", false),
                CreateColumn (typeof (string), tableInfo.TableAlias, "Name", false),
                CreateColumn (typeof (bool), tableInfo.TableAlias, "IsStarredCook", false),
                CreateColumn (typeof (bool), tableInfo.TableAlias, "IsFullTimeCook", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "SubstitutedID", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "KitchenID", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "KnifeID", false),
                CreateColumn (typeof (int), tableInfo.TableAlias, "KnifeClassID", false),
                CreateColumn (typeof (string), tableInfo.TableAlias, "LetterOfRecommendation", false)
            });
      }
      else if (type == typeof (Company))
      {
        return new SqlEntityDefinitionExpression (
            tableInfo.ItemType,
            tableInfo.TableAlias, null,
            e => e.GetColumn (typeof (int), "ID", true),
            new[]
            {
                CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
                CreateColumn (typeof (DateTime), tableInfo.TableAlias, "DateOfIncorporation", false)
            });
      }
      else if (type == typeof (Knife))
      {
        return new SqlEntityDefinitionExpression (
            tableInfo.ItemType,
            tableInfo.TableAlias, null,
            e => CreateMetaIDExpression (e.GetColumn (typeof (int), "ID", true), e.GetColumn (typeof (string), "ClassID", true)),
            new[]
            {
                CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
                CreateColumn (typeof (string), tableInfo.TableAlias, "ClassID", true),
                CreateColumn (typeof (double), tableInfo.TableAlias, "Sharpness", false)
            });
      }
      throw new UnmappedItemException (string.Format ("Type '{0}' is not supported by the MappingResolverStub.", type.Name));
    }

Usage Example

Пример #1
0
        private static void AppendInsertScript(StringBuilder sb, object entity)
        {
            var mappingResolver     = new MappingResolverStub();
            var generator           = new UniqueIdentifierGenerator();
            var resolvedTableInfo   = (ResolvedSimpleTableInfo)mappingResolver.ResolveTableInfo(new UnresolvedTableInfo(entity.GetType()), generator);
            var sqlEntityDefinition = mappingResolver.ResolveSimpleTableInfo(resolvedTableInfo, generator);
            var columnData          = (from c in sqlEntityDefinition.Columns
                                       let columnName = c.ColumnName
                                                        let columnValue =
                                           GetColumnValue(entity, mappingResolver, sqlEntityDefinition, columnName)
                                           select new { columnName, columnValue }).ToArray();

            var columnNames  = string.Join(",", columnData.Select(d => d.columnName));
            var columnValues = string.Join(",", columnData.Select(d => GetSqlValueString(d.columnValue)));

            sb.AppendFormat("INSERT INTO [{0}] ({1}) VALUES ({2});", resolvedTableInfo.TableName, columnNames, columnValues);
            sb.AppendLine();
        }
All Usage Examples Of Remotion.Linq.SqlBackend.UnitTests.MappingResolverStub::ResolveSimpleTableInfo