Comments (4)
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.
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.
See DataConnection.QueryProc
MySQL T4 could generate them, but I have no idea how to get sproc metadata for MySQL.
from linq2db.
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)
- Method not found in target type: Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools() HOT 4
- Linq2Db not all stored procedures scaffolding HOT 3
- Use custom property Getters in Linq queries HOT 5
- Remove `timestamp` "type" special handling in SQLite schema provider HOT 1
- [Association] with QueryExpressionMethod does not honor CanBeNull property HOT 3
- Connection pool depletion when using new DataContext(...), together with LoadWith and FirstOrDefault (or SingleOrDefault) HOT 6
- NotImplementedException when filtering on a sub-query HOT 9
- InheritanceMappingAttribute is working incorrectly when abstract class is present in inheritance tree HOT 5
- BulkCopy failure on CLOB HOT 1
- ConstantExpressions do not get parameterized in SQL statements HOT 1
- [QUESTION] Terminate a query by cancellation token HOT 5
- default-schemas not working
- Firebird different number datatype between constant or variable usage HOT 2
- Task-spawning code refactoring HOT 2
- WithOptions<T> looses CommandTimeout property
- Association property is null, while query is correct HOT 2
- Exception using Converter HOT 1
- Read some json values, Common Language Runtime detected an invalid program. HOT 5
- update documentation to show how to use fluent mapping
- Enum Array insert/update
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linq2db.