jonwagner / Insight.Database

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

Mixing and matching issue #440

Closed sadish-hub closed 4 years ago

sadish-hub commented 4 years ago

Describe the bug

2nd result set thenChildren is not working. in fact, it throws syntax error

Steps to reproduce

Results<Beer, Wine> results = c.QuerySql( @" SELECT FROM Beer WHERE Type="IPA" SELECT b.ID, g. FROM Glasses g JOIN RightGlass(...) ... SELECT FROM Wine WHERE Type="IPA" SELECT w.ID, g. FROM Glasses g JOIN RightGlass(...) ...", parameters, Query.Returns(Some.Records) .ThenChildren(Some.Records) .Then(Some.Records); .ThenChildren(Some.Records)

Expected behavior

Results<Beer, Wine> results = c.QuerySql( @" SELECT FROM Beer WHERE Type="IPA" SELECT b.ID, g. FROM Glasses g JOIN RightGlass(...) ... SELECT FROM Wine WHERE Type="IPA" SELECT w.ID, g. FROM Glasses g JOIN RightGlass(...) ...", parameters, Query.Returns(Some.Records) .ThenChildren(Some.Records) .Then(Some.Records) .ThenChildren(Some.Records)

Jaxelr commented 4 years ago

I am guessing you saw the example from the Wiki of Mixing and Matching, it is worth checking out since i dont think we have that specific scenario on the Sample Project, but, this brief sample works:

void Main()
{
    var conn = new SqlConnection("ConnectionHere");
    SqlInsightDbProvider.RegisterProvider();

    var response = conn.Query(@"SELECT 1 ParentId, 'Dad' Name, 'Rojas' SecondName
                    SELECT 1 ParentId, 4 ChildId, 'Child' ChildName, 'Rojas' SecondChildName;
                    SELECT 1 ParentId, 'Dad' Name, 'Rojas' SecondName
                    SELECT 1 ParentId, 4 ChildId, 'Child' ChildName, 'Rojas' SecondChildName", Parameters.Empty, 
        Query.Returns<Parent>()
        .ThenChildren(Some<Child>.Records)
        .Then(Some<AnotherParent>.Records)
        .ThenChildren(Some<Child>.Records), CommandType.Text);
}

class Parent
{
    public int ParentId { get; set; }
    public string Name { get; set; }
    public string SecondName { get; set; }
    public IEnumerable<Child> Childs { get; set; }
}

class AnotherParent
{
    public int ParentId { get; set; }
    public string Name { get; set; }
    public string SecondName { get; set; }
    public IEnumerable<Child> Childs { get; set; }
}

class Child
{
    public int ChildId { get; set; }
    public string ChildName { get; set; }
    public string SecondChildName { get; set; }
}

Do you have specific scenario that is not working? Could you provide some sample snippet?

sadish-hub commented 4 years ago

I'm sorry. I was using pretty old version of Insight packages. I upgraded it and its working now