jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
861 stars 145 forks source link

Question - Parent with a childen list of primitives #373

Closed michael-wolfenden closed 6 years ago

michael-wolfenden commented 6 years ago

Given the following:

public interface IRepository
{
    [Sql(@"
select 1 as Id, 'a' as Value union
select 1 as Id, 'b' as Value union
select 1 as Id, 'c' as Value
    ")]
    Task<Record> GetRecord();
}

public class Record
{
    public int Id;
    public List<string> Values;
}

Is there any way to make GetRecord() return a single Record with Id = 1 and Values = new List<string> { 'a', 'b', 'c'}

jonwagner commented 6 years ago

If you return the parent record in the first recordset, and children in a second recordset:

[Parent] SELECT 1 as Id
[Children] SELECT 1 as Id, 'a' as Value UNION...

Then you can tag the recordsets with:

[Sql(...)]
[Recordset(0, typeof(Record))]
[Recordset(1, typeof(String), IsChild=true, Into="Values")]
Task<Record> GetRecord();

I can't think of a simple way to do it without the parent record.

Do you have a specific use case you're trying to handle?

michael-wolfenden commented 6 years ago

Thanks for the response

In my scenario all the data for the parent and child could be retrieved in a single query, rather than repeating the same filtered query twice (once for the parent data (just an Id in this case) and once for the child data))