itechodev / codequery

CQ framework
0 stars 0 forks source link

Create SqlQuerable interface #2

Open wbijker opened 4 years ago

wbijker commented 4 years ago

Create a code interface to construct complex queries.

db.Person.Where(p => p.Id == 12).FetchSingle();

var res = db.Books
    .LeftJoin(db.Category)
    .InnerJoin(db.Author)
    .Select((category, book, author) => {
        Book = book.Name,
        Author = author.Name,
        Category = category?.Name ?? "No category"
    })
    .FetchMultiple();

Any amount of sub queries.

var a = db.Books
    .GroupBy(b => b.AuthorId)
    .Select(aggr => {
        AuthorId = aggr.Value,
        Count = aggr.Count()
    })
    .InnerJoin(b.Author, (b,a) => b.AuthorId == a.Id)
    .Select((book, author) => {

    })
    .FetchMultiple();

Multiple sub queries with aggregates
    var b = db.Enquiries
        .GroupBy(e => e.UserId);
        .Select(e => {
            UserID = e.Key,
            Used = e.Count()
        })
        .InnerJoin(db.Topup.., on, (l, r) => new { Used = L, Topup = r; })
        .InnerJoin(db.Users, .., (prev, r) => new { Userd = prev.Used, Topup = prev.Topup, Users = r) })
        .Select(u => {
            Used = u.Left.Right.Topups - u.left.Count(),
            Name = u.Right.Name,
        })