本文整理汇总了C#中Mapping.Table方法的典型用法代码示例。如果您正苦于以下问题:C# Mapping.Table方法的具体用法?C# Mapping.Table怎么用?C# Mapping.Table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapping
的用法示例。
在下文中一共展示了Mapping.Table方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateToObject_WhenCalledWithMultipeTablesUsingJoinIsJoinedCorrectly_SetsPropertiesCorrectly
public void GenerateToObject_WhenCalledWithMultipeTablesUsingJoinIsJoinedCorrectly_SetsPropertiesCorrectly()
{
IMapping mapping = new Mapping();
Action<TestClass, List<TestContent>> listSet = ( x, y ) => x.TestContents = y;
mapping.Join( listSet );
mapping.Table<TestClass>( 0 );
mapping.Table<TestContent>( 1 );
var classMapResult = new ClassMapResult
{
Mappings = (Mapping)mapping
};
var mockDataReader = new MockDataReader();
var table = mockDataReader.AddTable( "Length2" );
var contentTable = mockDataReader.AddTable( "Id", "Name" );
mockDataReader.AddRow( table, 1 );
mockDataReader.AddRow( contentTable, 1, "Name1" );
mockDataReader.AddRow( contentTable, 2, "Name2" );
var func = MappingGenerator.Generate<TestClass>( new MockDataReader(), classMapResult );
var result = func( mockDataReader, new Dictionary<MappingEnum, object>
{
{
MappingEnum.Join, new List<object>
{
listSet
}
}
}, new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>() );
Assert.AreEqual( 2, result.TestContents.Count );
Assert.AreEqual( "Name1", result.TestContents[ 0 ].Name );
Assert.AreEqual( "Name2", result.TestContents[ 1 ].Name );
}
示例2: GenerateToObject_WhenCalledWithVariableTableType_UsesCorrectType
public void GenerateToObject_WhenCalledWithVariableTableType_UsesCorrectType()
{
IMapping mapping = new Mapping();
Func<Result, BaseScore, bool> canJoin = ( r, b ) => r.Id == b.ResultId;
Action<Result, List<BaseScore>> listSet = ( r, b ) => r.Scores = b;
Func<IDataRecord, Type> variableTableType = dataRecord =>
{
switch ( dataRecord.GetInt32( 4 ) )
{
case 1:
return typeof( IntScore );
default:
return typeof( StringScore );
}
};
mapping.TableJoin<Result, BaseScore>( canJoin, listSet );
mapping.VariableTableType<BaseScore>( variableTableType );
mapping.Table<Result>( 0 );
mapping.Table<BaseScore>( 1 );
var classMapResult = new ClassMapResult
{
Mappings = (Mapping)mapping
};
var mockDataReader = new MockDataReader();
var results = mockDataReader.AddTable( "Id", "Name" );
var scores = mockDataReader.AddTable( "Id", "ResultId", "Value", "ValueString", "ResultType" );
mockDataReader.AddRow( results, 1, "Result 1" );
mockDataReader.AddRow( results, 2, "Result 2" );
mockDataReader.AddRow( scores, 1, 1, 10, "", 1 );
mockDataReader.AddRow( scores, 1, 2, DBNull.Value, "10", 2 );
var func = MappingGenerator.Generate<List<Result>>( new MockDataReader(), classMapResult );
var dictionary = new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>();
var result = func( mockDataReader, new Dictionary<MappingEnum, object>
{
{
MappingEnum.TableJoin, new List<TableJoinMap>
{
new TableJoinMap
{
CanJoin = canJoin,
ListSet = listSet
}
}
},
{
MappingEnum.VariableTableType, new Dictionary<Type, object>
{
{ typeof( BaseScore ), variableTableType }
}
}
}, dictionary );
Assert.AreEqual( 1, result[ 0 ].Id );
Assert.AreEqual( 2, result[ 1 ].Id );
Assert.AreEqual( 1, result[ 0 ].Scores.Count );
Assert.AreEqual( 1, result[ 1 ].Scores.Count );
Assert.IsInstanceOf<IntScore>( result[ 0 ].Scores[ 0 ] );
Assert.IsInstanceOf<StringScore>( result[ 1 ].Scores[ 0 ] );
Assert.AreEqual( 10, ( result[ 0 ].Scores[ 0 ] as IntScore ).Value );
Assert.AreEqual( "10", ( result[ 1 ].Scores[ 0 ] as StringScore ).ValueString );
}
示例3: GenerateToObject_WhenCalledWithPropertyMapColumnName_ReturnsCorrectData
public void GenerateToObject_WhenCalledWithPropertyMapColumnName_ReturnsCorrectData()
{
IMapping mapping = new Mapping();
mapping.Table<TestClass>( 0 );
mapping.PropertyMap<TestClass,string>( x => x.Name1, "Name" );
var classMapResult = new ClassMapResult
{
Mappings = (Mapping)mapping
};
var mockDataReader = new MockDataReader();
var scores = mockDataReader.AddTable( "Name" );
string expectedName = "The name";
mockDataReader.AddRow( scores, expectedName );
var func = MappingGenerator.Generate<List<TestClass>>( new MockDataReader(), classMapResult );
var dictionary = new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>();
var result = func( mockDataReader, new Dictionary<MappingEnum, object>
{
{
MappingEnum.PropertyMap, new Dictionary<PropertyInfo, PropertyMap>
{
{
typeof( TestClass ).GetProperty( "Name1" ), new PropertyMap( "Name" )
}
}
}
}, dictionary );
Assert.AreEqual( expectedName, result[ 0 ].Name1 );
}
示例4: GenerateToObject_WhenCalledWithVariableTableTypeAndPropertyMap_UsesPropertyMap
public void GenerateToObject_WhenCalledWithVariableTableTypeAndPropertyMap_UsesPropertyMap()
{
IMapping mapping = new Mapping();
Func<IDataRecord, Type> variableTableType = dataRecord => typeof( StringScore );
mapping.VariableTableType<BaseScore>( variableTableType );
Func<IDataRecord, string> action = dataRecord => "The Score Is: " + dataRecord.GetString( 2 );
mapping.PropertyMap<StringScore, String>( x => x.ValueString, action );
mapping.Table<BaseScore>( 0 );
var classMapResult = new ClassMapResult
{
Mappings = (Mapping)mapping
};
var mockDataReader = new MockDataReader();
var scores = mockDataReader.AddTable( "Id", "ResultId", "ValueString", "ResultType" );
mockDataReader.AddRow( scores, 1, 1, "10", 2 );
var func = MappingGenerator.Generate<List<BaseScore>>( new MockDataReader(), classMapResult );
var dictionary = new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>();
var result = func( mockDataReader, new Dictionary<MappingEnum, object>
{
{
MappingEnum.VariableTableType, new Dictionary<Type, object>
{
{ typeof( BaseScore ), variableTableType }
}
},
{
MappingEnum.PropertyMap, new Dictionary<PropertyInfo, PropertyMap>
{
{
typeof( StringScore ).GetProperty( "ValueString" ), new PropertyMap( action )
}
}
}
}, dictionary );
Assert.AreEqual( 1, result[ 0 ].Id );
Assert.IsInstanceOf<StringScore>( result[ 0 ] );
Assert.AreEqual( "The Score Is: 10", ( result[ 0 ] as StringScore ).ValueString );
}
示例5: GenerateToObject_WhenCalledWithMultipeTablesWithResultingDictionary_FillsDictionaryCorrectly
public void GenerateToObject_WhenCalledWithMultipeTablesWithResultingDictionary_FillsDictionaryCorrectly()
{
IMapping mapping = new Mapping();
Func<TestClass, dynamic, bool> condition = ( @class, o ) => true;
Action<TestClass, Dictionary<int, string>> destination = ( @class, values ) => @class.TestContentDictionary = values;
mapping.AddJoin( x =>
x.DictionaryTableJoin<TestClass>()
.Condition( condition )
.KeyColumn( "Id" )
.ValueColumn( "Name" )
.SetDestinationProperty( destination )
.ChildTable( 1 ) );
mapping.Table<TestClass>( 0 );
var classMapResult = new ClassMapResult
{
Mappings = (Mapping)mapping
};
var mockDataReader = new MockDataReader();
var table = mockDataReader.AddTable( "Length2", "TestContentId" );
var contentTable = mockDataReader.AddTable( "Id", "Name" );
mockDataReader.AddRow( table, 1, 1 );
mockDataReader.AddRow( contentTable, 1, "Name1" );
mockDataReader.AddRow( contentTable, 2, "Name2" );
var func = MappingGenerator.Generate<TestClass>( new MockDataReader(), classMapResult );
var result = func( mockDataReader, new Dictionary<MappingEnum, object>
{
{
MappingEnum.DictionaryJoin, new List<KeyValuePair<object, object>>
{
new KeyValuePair<object, object>( condition, destination )
}
}
}, new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>() );
Assert.AreEqual( 2, result.TestContentDictionary.Count );
Assert.AreEqual( "Name1", result.TestContentDictionary[ 1 ] );
Assert.AreEqual( "Name2", result.TestContentDictionary[ 2 ] );
}