Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it Possible to use Stored Proc result without defined POCO? #109

Closed
vl1969 opened this issue Mar 30, 2012 · 1 comment
Closed

Is it Possible to use Stored Proc result without defined POCO? #109

vl1969 opened this issue Mar 30, 2012 · 1 comment
Labels

Comments

@vl1969
Copy link

vl1969 commented Mar 30, 2012

Hi, All good people on this site.

a little help would be greatly appreciated :-)

SETUP:

  1. VS 2010 development solution (ALL C# projects) 3 tier solutions (App/Model/BLL/DLL)
    a. database is SQL 2010
  2. currently using Custom DAL and in process of testing PetaPoco for replacement.
  3. includes report module (rdls reports) created/displayed from C# report viewer
    a. all reports are generic and rely on DataTables currently returned from Stored Procedures calls only
    b. data is collected and processed with in stored procedure(s) no physical reporting tables exists.

here is my issue:
I have an existing project that I am trying to convert to PetaPoco DAL instead of my custom coded DAL.

I have added all files and references and for most of my testing PP is working (I have not done a full fledge implementation as there is a lot of strange dependent code for existing DAL but eventually PP will replace all my needs for DB access)
I understand how most of the thing work with PetaPoco when using the POCOs from datatables (I have included the T4 template that generates all POCOs from database.)
But I have a reporting project that does not use any tables directly. All of the application currently use Stored Procedures for All data access and manipulations, and the reporting module rely only on Stored procedures for data.
no POCOs exists.
Now I can call the SP like so (I have tried all methods I could think of so far)

"new Database(Config.MainDbConnectionName).ExecuteProc("MetalCostByMonthReport",
new
{
@ReportDate = CurrentReportDate,
@TargetMetal = targetMetal,
@MetalPrice =
Helper.GetValidatedValue
(userInput.Text),
@GenerateInvoice = regenerate
}).
Rows);"

which returns an ExpandoObject but I can not use it.
my grid wont bind to it directly and when I try to convert the result into DataTabel (which what the underlying code expects back for binding to datagridview)

using this code found on one of the forums

///

    /// Extension method to convert dynamic data to a DataTable. Useful for databinding.
    /// </summary>


    /// <param name="items"></param>
    /// <returns>A DataTable with the copied dynamic data.</returns>
    public static DataTable DynamicToDataTable( IEnumerable<dynamic> items)
    {
        if (items.ToArray().Count() == 0) return null;
        var dt = new DataTable();
        dt.Columns.AddRange(((IDictionary<string, object>)items.FirstOrDefault()).Keys.Select(k => new DataColumn(k)).ToArray());

        foreach (var record  in items)
        {
            dt.Rows.Add(((IDictionary<string, object>) record).Values.ToArray());
        }
        dt.EndLoadData();
        return dt;
    }

I get an error in the report as if data is bad.

I have verified that the data is GOOD (the proc is called using the old DAL and returns the same data)
I can see the data in the dataTable as well.
but report cuts out approximately half way through and nothing.

here are the questions I have:

  1. is there a better way in calling the SP with PP
  2. can I use PP without predefined POCOs
  3. Any at all sugestions what am I doing wrong

Thanks

@pleb pleb added the question label Dec 4, 2015
@pleb
Copy link
Member

pleb commented Dec 5, 2015

I'm sorry that your issue has been left for so long. In an effort to reboot PetaPoco your issue has been closed. If you think this is still a problem. Please feel free to open and another issue. Please pass the word on that PetaPoco is back. We're looking for people #204.

@pleb pleb closed this as completed Dec 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants