public void DirectBindingTest() { // Map ObjectA to ObjectB with a direct bind to Id Func <Expression, MemberAssignment[]> assignments = sourceParam => { return(new MemberAssignment[] { sourceParam.DirectBind <ObjectB>("Id") }); }; ObjectB obj = listOfObjectA.Select(assignments.Model <ObjectA, ObjectB>().Compile()).FirstOrDefault(); Assert.AreEqual(15, obj.Id); }
public void TestAny() { // Setup the source param ParameterExpression sourceParam = Expression.Parameter(typeof(ObjectD), "source"); // Setup the model bindings MemberAssignment[] assignments = new MemberAssignment[] { sourceParam.DirectBind <ObjectF>(nameof(ObjectF.Id)), sourceParam.BindHasAny <ObjectF, ObjectA>(nameof(ObjectF.HasChildren), (param) => { return(Expression.Equal( Expression.Property(param, nameof(ObjectA.Id)), Expression.Constant(1) )); }, nameof(ObjectD.ListOfA)) }; // Select the objectF from the objectD list ObjectF obj = Objects .Select(Expression.Lambda <Func <ObjectD, ObjectF> >( Expression.MemberInit(Expression.New(typeof(ObjectF)), assignments) , sourceParam).Compile()).FirstOrDefault(); // Verify data Assert.IsNotNull(obj); Assert.IsTrue(obj.HasChildren); Assert.AreEqual(1, obj.Id); }