Giter Site home page Giter Site logo

Comments (4)

pebezo avatar pebezo commented on April 28, 2024 7

I got it working:

        using (var db = new Db())
        {
            var query = db.QueryProc<TheClassThatHoldsTheValues>("the_name_of_my_stored_procedure",
                new DataParameter("param1", value1), 
                new DataParameter("param2", value2),
                etc...
                );

            return query.ToList();
        }

And in my BO class (TheClassThatHoldsTheValues in the example above) I was able to use [Column(Name = "actual_column_name_returned_by_stored_procedure")] which is pretty nice.

Thanks for your help.

from linq2db.

welldtr avatar welldtr commented on April 28, 2024 1

BTW, if you guys need, I made an extension to write this with "less code"

using System.Collections.Generic;
using System.Linq;

namespace LinqToDB.Data
{
    static class DataConnectionExtension
    {
        public static List<T> QueryProc<T>(this DataConnection db, string proc, object values)
        {
            List<DataParameter> parameters = new List<DataParameter>();
            foreach (var prop in values.GetType().GetProperties())
            {
                var name = prop.Name;
                var value = prop.GetValue(values);
                parameters.Add(new DataParameter(name, value));
            }
            var result = db.QueryProc<T>(proc, parameters.ToArray());
            return result.ToList();
        }
    }
}

So you can call this way:


            var query = db.QueryProc<YourReturn>("your_proc_name", new
            {
                my1StParameterName = "my value 1",
                otherNameYouWant = 123123
            });

from linq2db.

igor-tkachev avatar igor-tkachev commented on April 28, 2024

See DataConnection.QueryProc

MySQL T4 could generate them, but I have no idea how to get sproc metadata for MySQL.

from linq2db.

jogibear9988 avatar jogibear9988 commented on April 28, 2024

i think maybe we should generate a expression tree and compile it for each anonymous type and cache it in a dictionary, so reflection is only needed once. Or maybe we create a second function "queryprocwithcache"

from linq2db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.