sapiens / SqlFu

Fast and versatile .net core data mapper/micro-orm
Other
229 stars 50 forks source link

multiple result set support #6

Closed Begl4 closed 11 years ago

Begl4 commented 12 years ago

Are multiple result set support posibile with SqlFu ?

Example :

public class Data { public int Int1 { get; set; } public string Str { get; set; } public int Int2 { get; set; } }

var data2 = db.FetchMultiple<int, string, int, Data>((x,y,z) => { var data = new Data {Int1 = x[0], Str = y[0], Int2 = z[0]}; return data; }, "select 1;select 'hi';select 5");

And how to populate Posts in Blog :

public class Blog { public int ID { get; set; } public string Topic { get; set; } public List < Post > Posts { get; set; } }

public class Post { public int ID { get; set; } public string Comment { get; set; } }

sapiens commented 12 years ago

Not at this moment, however multi result set support is on my to-do list, but I can't tell you when I'll add this feature.

Begl4 commented 12 years ago

Ok no rush. How about second question, maping Blog and especialy prop Posts in Blog ?

PS :very like SQLFu

sapiens commented 12 years ago

Those will have to be done manually for now, SqlFu doesn't handle collections in multi poco mapping.

Begl4 commented 12 years ago

Ok,Thx for replay.

ventaur commented 11 years ago

Did this get implemented? I'd happily settle for partial support via something like the following:

var reader = db.WithSql(sql, new {...}).ExecuteReader();

At least that way, I could iterate the reader manually and use reader.NextResult() for multiple result sets. WithSql() would still save me a lot of code setting up parameters, command, connection, etc.

sapiens commented 11 years ago

You could get 'partial' support, by checking out the devel branch where there is an extension method (was internal, made it public now) that gives you a command to use

using (var cmd = db.CreateAndSetupCommand(sql, args))
            {
               //do whatever
            }
ventaur commented 11 years ago

That's great! Thank you.

I went one step further (to save even more code) and made PocoFactory.GetPocoMapper() public . Now, I can execute the command to a reader, get a mapper, map to an object from the reader, get the next result, and repeat. I'm not sure if that's something you want to consider to really give pretty good partial support for this type of thing.

Lastly, as my way of pulling this off, I created a few new extension methods with signatures like the following:

public static Tuple<List<T1>, List<T2>> Fetch<T1, T2>(...) {...}
public static Tuple<List<T1>, List<T2>, List<T3>> Fetch<T1, T2, T3>(...) {...}
public static Tuple<List<T1>, List<T2>, List<T3>, List<T4>> Fetch<T1, T2, T3, T4>(...) {...}

It's not the most elegant signature and I usually frown on using Tuple<>, but the methods are short to pull off what I needed to for now.

sapiens commented 11 years ago

If you could send me a pull request, maybe we can make it a full feature or something.

ventaur commented 11 years ago

Mihai,

I will do just that as soon as I'm clear of my upcoming deadline. Thanks again for getting a change that really helped out up so quickly earlier.

I'll be in touch via Github!

-Matt

On Thu, Jul 25, 2013 at 3:09 AM, Mihai Mogosanu notifications@github.comwrote:

If you could send me a pull request, maybe we can make it a full feature or something.

— Reply to this email directly or view it on GitHubhttps://github.com/sapiens/SqlFu/issues/6#issuecomment-21536913 .