No, anonymous types can't be returned. You can bind an ASP.Net GridView to a Dictionary. Is that not working for you?.
________________________________ From: Stelio Macumbe <stelio.macu...@gmail.com> To: mybatisnet-user@googlegroups.com Sent: Saturday, September 1, 2012 4:25 AM Subject: Can ibatis.NET return anonymous type
Hi, I am writing an application which will perform dozens of reporting queries , since these queries might change frequently I find it unpractical to create a class for each of them, so I am trying to map them to an anonymous class like this:
The objects are created but there are no properties in then. I know I could use a Dictionary or Hashtable but the problem is that the list will later be bound to a GridView which does not support dictionaries.
Is it possible to create the objects with the query columns mapped as properties ?
> No, anonymous types can't be returned. You can bind an ASP.Net GridView to
> a Dictionary. Is that not working for you?.
> ------------------------------
> *From:* Stelio Macumbe <stelio.macu...@gmail.com>
> *To:* mybatisnet-user@googlegroups.com
> *Sent:* Saturday, September 1, 2012 4:25 AM
> *Subject:* Can ibatis.NET return anonymous type
> Hi,
> I am writing an application which will perform dozens of reporting queries
> , since these queries might change frequently I find it unpractical to
> create a class for each of them, so I am trying to map them to an anonymous
> class like this:
> The objects are created but there are no properties in then. I know I
> could use a Dictionary or Hashtable but the problem is that the list will
> later be bound to a GridView which does not support dictionaries.
> Is it possible to create the objects with the query columns mapped as
> properties ?
On 01/set/2012, at 10:25, Stelio Macumbe <stelio.macu...@gmail.com> wrote:
> Hi,
> I am writing an application which will perform dozens of reporting queries , since these queries might change frequently I find it unpractical to create a class for each of them, so I am trying to map them to an anonymous class like this:
> The objects are created but there are no properties in then. I know I could use a Dictionary or Hashtable but the problem is that the list will later be bound to a GridView which does not support dictionaries.
> Is it possible to create the objects with the query columns mapped as properties ?
i have found that the best way is to return a DataTable. ASAP I will post a simple piece of code in order to return a DataTable exploiting all the good stuff of mybatis.
> On 01/set/2012, at 10:25, Stelio Macumbe <stelio.macu...@gmail.com> wrote:
> > Hi,
> > I am writing an application which will perform dozens of reporting
> queries , since these queries might change frequently I find it unpractical
> to create a class for each of them, so I am trying to map them to an
> anonymous class like this:
> > The objects are created but there are no properties in then. I know I
> could use a Dictionary or Hashtable but the problem is that the list will
> later be bound to a GridView which does not support dictionaries.
> > Is it possible to create the objects with the query columns mapped as
> properties ?
> i have found that the best way is to return a DataTable. ASAP I will post
> a simple piece of code in order to return a DataTable exploiting all the
> good stuff of mybatis.
Actually it is a bit quick and dirty and should be refined and provided
with better error handling. This code is implemented in my DAO class
outside myBatis.
I usually map the resultClass as map, but it is not important at this point
(when doing reporting I often use the same select statement used for
mapping class objects.
Heavy reports require specially crafted and optimized sql queries (lots of
join. groupby etc etc) and have them bind to datatable is a must-have in
order to naturally bind to report documents or when lists of objects leads
to performance issues.
In the code the dataTableName parameter could be optional, cannot remember
if I use in client code...
---------------------------------------
public DataTable SelectDataTable(String dataTableName, string
statementName, object parameters)
{
DataTable dt = null;
if (!String.IsNullOrEmpty(dataTableName))
dt = new DataTable(dataTableName);
else
dt = new DataTable();
> Andrea, if you commit it to the 1.X branch, we can do a patch release.
> On Tue, Sep 4, 2012 at 11:37 AM, Andrea Tassinari <
> andrea.tassin...@gmail.com> wrote:
>> On 01/set/2012, at 10:25, Stelio Macumbe <stelio.macu...@gmail.com>
>> wrote:
>> > Hi,
>> > I am writing an application which will perform dozens of reporting
>> queries , since these queries might change frequently I find it unpractical
>> to create a class for each of them, so I am trying to map them to an
>> anonymous class like this:
>> > The objects are created but there are no properties in then. I know I
>> could use a Dictionary or Hashtable but the problem is that the list will
>> later be bound to a GridView which does not support dictionaries.
>> > Is it possible to create the objects with the query columns mapped as
>> properties ?
>> i have found that the best way is to return a DataTable. ASAP I will post
>> a simple piece of code in order to return a DataTable exploiting all the
>> good stuff of mybatis.
It is actually a winforms application, I tried to bind a dictionary to a
gridview but it doesn't work, after some research I learned it is not
possible
Greetings
On Tue, Sep 4, 2012 at 8:09 AM, Ron Grabowski <rongrabow...@yahoo.com>wrote:
> No, anonymous types can't be returned. You can bind an ASP.Net GridView to
> a Dictionary. Is that not working for you?.
> ------------------------------
> *From:* Stelio Macumbe <stelio.macu...@gmail.com>
> *To:* mybatisnet-user@googlegroups.com
> *Sent:* Saturday, September 1, 2012 4:25 AM
> *Subject:* Can ibatis.NET return anonymous type
> Hi,
> I am writing an application which will perform dozens of reporting queries
> , since these queries might change frequently I find it unpractical to
> create a class for each of them, so I am trying to map them to an anonymous
> class like this:
> The objects are created but there are no properties in then. I know I
> could use a Dictionary or Hashtable but the problem is that the list will
> later be bound to a GridView which does not support dictionaries.
> Is it possible to create the objects with the query columns mapped as
> properties ?
I will give it a try, I am surprised I haven't considered using data tables , probably because I am trying to forget the nightmare that was developing with data sets . Still it would be nice if Ibatis could generate anonymous objects, it would feel more ibatishy. Do you have any idea if there is some part I could hack in and accomplish that ? Some extension, plugin , helper class ,etc ?
On Tuesday, September 4, 2012 1:01:24 PM UTC-7, AndreaT wrote:
> Actually it is a bit quick and dirty and should be refined and provided > with better error handling. This code is implemented in my DAO class > outside myBatis.
> I usually map the resultClass as map, but it is not important at this > point (when doing reporting I often use the same select statement used for > mapping class objects.
> Heavy reports require specially crafted and optimized sql queries (lots of > join. groupby etc etc) and have them bind to datatable is a must-have in > order to naturally bind to report documents or when lists of objects leads > to performance issues.
> In the code the dataTableName parameter could be optional, cannot remember > if I use in client code...
> --------------------------------------- > public DataTable SelectDataTable(String dataTableName, string > statementName, object parameters) > { > DataTable dt = null; > if (!String.IsNullOrEmpty(dataTableName)) > dt = new DataTable(dataTableName); > else > dt = new DataTable();
> using (scope.IDbCommand) > { > dt.Load(scope.IDbCommand.ExecuteReader());
> }
> _mapper.CloseConnection();
> return dt; > } > ----------------
> this is not my stuff, I found somewhere in the web and just adapted to my > needs.
> hope this help
> andrea
> On Tue, Sep 4, 2012 at 9:06 PM, Michael McCurrey <mmcc...@gmail.com<javascript:> > > wrote:
>> Andrea, if you commit it to the 1.X branch, we can do a patch release.
>> On Tue, Sep 4, 2012 at 11:37 AM, Andrea Tassinari <andrea.t...@gmail.com<javascript:> >> > wrote:
>>> On 01/set/2012, at 10:25, Stelio Macumbe <stelio....@gmail.com<javascript:>> >>> wrote:
>>> > Hi, >>> > I am writing an application which will perform dozens of reporting >>> queries , since these queries might change frequently I find it unpractical >>> to create a class for each of them, so I am trying to map them to an >>> anonymous class like this:
>>> > The objects are created but there are no properties in then. I know I >>> could use a Dictionary or Hashtable but the problem is that the list will >>> later be bound to a GridView which does not support dictionaries.
>>> > Is it possible to create the objects with the query columns mapped as >>> properties ?
>>> i have found that the best way is to return a DataTable. ASAP I will >>> post a simple piece of code in order to return a DataTable exploiting all >>> the good stuff of mybatis.
On Tuesday, September 4, 2012 1:01:24 PM UTC-7, AndreaT wrote:
> Actually it is a bit quick and dirty and should be refined and provided > with better error handling. This code is implemented in my DAO class > outside myBatis.
> I usually map the resultClass as map, but it is not important at this > point (when doing reporting I often use the same select statement used for > mapping class objects.
> Heavy reports require specially crafted and optimized sql queries (lots of > join. groupby etc etc) and have them bind to datatable is a must-have in > order to naturally bind to report documents or when lists of objects leads > to performance issues.
> In the code the dataTableName parameter could be optional, cannot remember > if I use in client code...
> --------------------------------------- > public DataTable SelectDataTable(String dataTableName, string > statementName, object parameters) > { > DataTable dt = null; > if (!String.IsNullOrEmpty(dataTableName)) > dt = new DataTable(dataTableName); > else > dt = new DataTable();
> using (scope.IDbCommand) > { > dt.Load(scope.IDbCommand.ExecuteReader());
> }
> _mapper.CloseConnection();
> return dt; > } > ----------------
> this is not my stuff, I found somewhere in the web and just adapted to my > needs.
> hope this help
> andrea
> On Tue, Sep 4, 2012 at 9:06 PM, Michael McCurrey <mmcc...@gmail.com<javascript:> > > wrote:
>> Andrea, if you commit it to the 1.X branch, we can do a patch release.
>> On Tue, Sep 4, 2012 at 11:37 AM, Andrea Tassinari <andrea.t...@gmail.com<javascript:> >> > wrote:
>>> On 01/set/2012, at 10:25, Stelio Macumbe <stelio....@gmail.com<javascript:>> >>> wrote:
>>> > Hi, >>> > I am writing an application which will perform dozens of reporting >>> queries , since these queries might change frequently I find it unpractical >>> to create a class for each of them, so I am trying to map them to an >>> anonymous class like this:
>>> > The objects are created but there are no properties in then. I know I >>> could use a Dictionary or Hashtable but the problem is that the list will >>> later be bound to a GridView which does not support dictionaries.
>>> > Is it possible to create the objects with the query columns mapped as >>> properties ?
>>> i have found that the best way is to return a DataTable. ASAP I will >>> post a simple piece of code in order to return a DataTable exploiting all >>> the good stuff of mybatis.
On 09/set/2012, at 08:35, Stelio Macumbe <stelio.macu...@gmail.com> wrote:
> Hi Andreas,
> What would cause a list of objects lead to performance issues ? Aren't POCOs lighter than data tables ?
yes poco are lighter in term of memory, but consider doing statistics where you have to load dozens or even hundreds of objects and consider how ibatis maps fields to property. for some reporting porpouses i prefer not to have the goods of object representation in favor if a flat bidimentional data structure (old style). we have built an end user report builder where end user can customize or create his own report from base reports that have builtin sample data or query.
for some other reports ( invoices, orders etc) we use list of objects.
> On Tuesday, September 4, 2012 1:01:24 PM UTC-7, AndreaT wrote:
> Actually it is a bit quick and dirty and should be refined and provided with better error handling. This code is implemented in my DAO class outside myBatis.
> I usually map the resultClass as map, but it is not important at this point (when doing reporting I often use the same select statement used for mapping class objects.
> Heavy reports require specially crafted and optimized sql queries (lots of join. groupby etc etc) and have them bind to datatable is a must-have in order to naturally bind to report documents or when lists of objects leads to performance issues.
> In the code the dataTableName parameter could be optional, cannot remember if I use in client code...
> ---------------------------------------
> public DataTable SelectDataTable(String dataTableName, string statementName, object parameters)
> {
> DataTable dt = null;
> if (!String.IsNullOrEmpty(dataTableName))
> dt = new DataTable(dataTableName);
> else
> dt = new DataTable();
> using (scope.IDbCommand)
> {
> dt.Load(scope.IDbCommand.ExecuteReader());
> }
> _mapper.CloseConnection();
> return dt;
> }
> ----------------
> this is not my stuff, I found somewhere in the web and just adapted to my needs.
> hope this help
> andrea
> On Tue, Sep 4, 2012 at 9:06 PM, Michael McCurrey <mmcc...@gmail.com> wrote:
> Andrea, if you commit it to the 1.X branch, we can do a patch release.
> On Tue, Sep 4, 2012 at 11:37 AM, Andrea Tassinari <andrea.t...@gmail.com> wrote:
> On 01/set/2012, at 10:25, Stelio Macumbe <stelio....@gmail.com> wrote:
> > Hi,
> > I am writing an application which will perform dozens of reporting queries , since these queries might change frequently I find it unpractical to create a class for each of them, so I am trying to map them to an anonymous class like this:
> > The objects are created but there are no properties in then. I know I could use a Dictionary or Hashtable but the problem is that the list will later be bound to a GridView which does not support dictionaries.
> > Is it possible to create the objects with the query columns mapped as properties ?
> i have found that the best way is to return a DataTable. ASAP I will post a simple piece of code in order to return a DataTable exploiting all the good stuff of mybatis.