Pergunta
I have a result set that might look like this:
ID (no column name) anotherID
---- ---------------- ----------
1 super 3
1 super 4
3 duper 6
4 really 7
4 really 8
I have 2 issues:
First: How do I use dapper with a column with no name?
Second: I want to have a parent child relationship such that I get 3 objects each with a list of anotherID's for example:
public class MyObject
{
public int ID
public string Name
public int[] Children
}
Solução
Well, un-named columns are not supported by dapper. I never really saw a reason for them.
I guess we could build support for:
class Foo { [ColumnNumber(1)] public string Name {get;set;} }
The trouble is that it introduces a very fragile method of querying which I strongly dislike, passing a directive to Query
is just as clunky.
However, if you are happy to change the way you grab the results you could work around this.
var grid = QueryMultiple(@"set nocount on
declare @t table(Id int, Name nvarchar(max), AnotherId int)
insert @t
exec proc
set nocount off
select Id, Name from @t
select Id, AnotherId from @t
");
Then use the technique here to multi map: Multi-Mapper to create object hierarchy
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow