예제 #1
0
        public void AnonymousTypeKeyInfoIsEmptyThatCannot()
        {
            var keyInfo = AnonymousTypeKeyInfo.Create((Member m) => new { m.GroupId2 });

            Assert.IsFalse(
                keyInfo.IsEmptyKey(
                    new
            {
                GroupId2 = 1
            }));
        }
예제 #2
0
        public void AnonymousTypeKeyInfoIsEmpty()
        {
            var keyInfo = AnonymousTypeKeyInfo.Create((Member m) => new { m.GroupId, m.GroupId2 });

            Assert.IsTrue(
                keyInfo.IsEmptyKey(
                    new
            {
                GroupId  = (int?)null,
                GroupId2 = 1
            }));

            Assert.IsFalse(
                keyInfo.IsEmptyKey(
                    new
            {
                GroupId  = (int?)1,
                GroupId2 = 2
            }));
        }
        public bool TryCreateKeyInfo <TEntity, TKey>(
            Expression <Func <TEntity, TKey> > keySelector,
            out IKeyInfo <TEntity, TKey> result) where TEntity : class
        {
            if (!ReflectionHelper.IsAnonymousType(typeof(TKey)))
            {
                result = null;
                return(false);
            }

            IKeyInfoHelper helper = AnonymousTypeKeyInfo <TEntity, TKey> .KeyInfoHelper;

            MemberInfo[] members;

            if (!helper.TryParseKeySelectorExpression(keySelector.Body, true, out members))
            {
                result = null;
                return(false);
            }

            result = new AnonymousTypeKeyInfo <TEntity, TKey>(members);
            return(true);
        }
예제 #4
0
 public void AnonymousTypeKeyInfoInvalidCreation()
 {
     // Casting must not be used in the selector expression
     AnonymousTypeKeyInfo.Create((Member m) => new { Id1 = m.GroupId, Id2 = (long)m.GroupId2 });
 }
예제 #5
0
        public void AnonymousTypeKeyInfoCreation()
        {
            var keyInfo = AnonymousTypeKeyInfo.Create((Member m) => new { m.GroupId, m.GroupId2 });

            Assert.AreEqual(2, keyInfo.EntityKeyMembers.Length);
        }