0
votes

I want to use dapper to query a complex entity from database.

Ex. Job is top level entity I want to query.

public class Job
{
    public User User { get; set; }
}
public class Account
{
}

public class Roles
{
    public IList<Schedule> Schedules { get; set; }
}


public class Devices
{
    public IList<Roles> Roles { get; set; }
    public IList<Account> Accounts { get; set; }
}

public class Schedule
{

}
public class User
{
    public IList<Account> Accounts { get; set; }
    public Profile Profile { get; set; }
}
public class Profile
{
    public IList<Account> Accounts { get; set; }
}

Is this even possible with dapper, if it is then is it worth using dapper for this or should I use some other ORM (EF, LLBLGen, NH)?

1
Why all the hate people? Down voters plz share your gripe. - Mayank
I didn't downvote but I assume the reason is because it is unclear from your example as to what you are asking. Can you provide a code example? - kttii
@kttii see updates. - Mayank
How are you implementing the multimap in your code? - kttii
@kttii I am currently using NH and trying to move away from it as it is super slow. - Mayank

1 Answers

0
votes

I believe you are asking how to implement MultiMapping in Dapper.

You can pass more than one model like so:

var sql = @"select * from Product p 
            inner join Customer c on p.CustomerId = c.CustomerId 
            order by p.ProductName";

var item = connection.Query<ProductItem, Customer, ProductItem>(sql,
        (p, c) => { p.Customer = c; return p; }, splitOn: "CustomerId").First();

Reference: Correct use of Multimapping in Dapper