Пример #1
0
        public void IdConventionExpression_Returns_EntityWithId()
        {
            using (var uowStub = Stub.CreateMemoryUoW(typeof(Author)))
            {
                uowStub.AddAuthors(5);
                var qrit = new IdQriteria <Int32> {
                    Id = 3
                };
                var expr = ConventionBuilder <Author>
                           .IdFilterExpression(qrit);

                var actual = uowStub.Linq.Query <Author>()
                             .Where(expr)
                             .Cast <Author>()
                             .Single();

                Assert.AreEqual(qrit.Id, actual.Id);
            }
        }
Пример #2
0
        public void IdStringConventionExpression_Returns_EntityWithId()
        {
            using (var uow = Stub.CreateMemoryUoW(typeof(BookAuthor)))
            {
                uow.Add(new BookAuthor(new Book(1, "Book 1"), new Author(1, "Author 1")));
                uow.Add(new BookAuthor(new Book(2, "Book 2"), new Author(1, "Author 1")));
                uow.Add(new BookAuthor(new Book(3, "Book 2"), new Author(2, "Author 2")));

                var qrit = new IdQriteria <String> {
                    Id = "2-1"
                };
                var expr = ConventionBuilder <BookAuthor>
                           .IdFilterExpression(qrit);

                var actual = uow.Linq.Query <BookAuthor>().Where(expr)
                             .Cast <BookAuthor>()
                             .Single();

                Assert.AreEqual(qrit.Id, actual.Id);
            }
        }
Пример #3
0
 public static IQueryable <TSubject> IdFilter(IQueryable <TSubject> query, IHasId qrit)
 => query.Where(ConventionBuilder <TSubject> .IdFilterExpression(qrit));
Пример #4
0
 public IQueryable Query(ILinqProvider linqProvider, IHasId qrit)
 => linqProvider.Query <TEntity>()
 .Where(ConventionBuilder <TEntity> .IdFilterExpression(qrit));