当前位置: 首页>>代码示例>>C#>>正文


C# Mapping.AddJoin方法代码示例

本文整理汇总了C#中Mapping.AddJoin方法的典型用法代码示例。如果您正苦于以下问题:C# Mapping.AddJoin方法的具体用法?C# Mapping.AddJoin怎么用?C# Mapping.AddJoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mapping的用法示例。


在下文中一共展示了Mapping.AddJoin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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 ] );
        }
开发者ID:jrote1,项目名称:SqlObjectHydrator,代码行数:45,代码来源:MappingGeneratorTests.cs


注:本文中的Mapping.AddJoin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。