Пример #1
0
        public void WhereSelectItemTestByName()
        {
            Func <Expression, Expression> predicateGenerator = param =>
                                                               Expression.Equal(Expression.Property(param, "Id"), Expression.Constant(1));

            MemberAssignment[] assignments = new MemberAssignment[]
            {
                sourceParam.BindFilteredItem <ObjectE, ObjectA, ObjectB>("ObjectB", "ListOfA", predicateGenerator, ObjectB.FromObjectA)
            };

            ObjectE obj = listOfObjectD.Select(Expression.Lambda <Func <ObjectD, ObjectE> >(
                                                   Expression.MemberInit(Expression.New(typeof(ObjectE)), assignments)
                                                   , sourceParam).Compile()).FirstOrDefault();

            Assert.IsNotNull(obj.ObjectB);
            Assert.AreEqual(1, obj.ObjectB.Id);
        }