public void AnonymousTypeKeyInfoIsEmptyThatCannot() { var keyInfo = AnonymousTypeKeyInfo.Create((Member m) => new { m.GroupId2 }); Assert.IsFalse( keyInfo.IsEmptyKey( new { GroupId2 = 1 })); }
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); }
public void AnonymousTypeKeyInfoInvalidCreation() { // Casting must not be used in the selector expression AnonymousTypeKeyInfo.Create((Member m) => new { Id1 = m.GroupId, Id2 = (long)m.GroupId2 }); }
public void AnonymousTypeKeyInfoCreation() { var keyInfo = AnonymousTypeKeyInfo.Create((Member m) => new { m.GroupId, m.GroupId2 }); Assert.AreEqual(2, keyInfo.EntityKeyMembers.Length); }