FAQ Database Discussion Community


Bulk Insert in multiple relational tables using Dapper .Net-using scope identity

sql,sql-server,c#-4.0,dapper
I need to import millions of records in multiple sql server relational tables. TableA(Aid(pk),Name,Color)----return id using scope identity TableB(Bid,Aid(fk),Name)---Here we need to insert Aid(pk) which we got using scocpe Identity How I can do bulk insert of collection of millions of records using dapper in one single Insert statement...

Dapper nested object query - not populating all properties

c#,linq,dapper
I am trying to return a flat result set into a nested object with Dapper.NET (EmergingIssue contains both Reason and Status objects), but the query is not populating all the columns. See POCOs below: public class EmergingIssue { public string Category; public string Brand; public string Sku; public string SkuDesc;...

Using EF and other Dapper ORM in same project - drawbacks [closed]

asp.net,asp.net-mvc,asp.net-identity,projects-and-solutions,dapper
I am about to start a new project and I have a little dillema. App require asp identity for security and dapper as orm. My plan is to use default asp web app template with identity that use entity framework and for all business data access use dapper. This means...

How to fill dropdownlist in MVC-4 using dapper

asp.net-mvc,asp.net-mvc-4,dapper
I filled Drop Down List in MVC which is working fine but now I want to do it using Dapper but got stuck. DropDownList in MVC without Dapper Controller [HttpPost] public ActionResult Create(User ur) { string str = @"Data Source=DEV_3\SQLEXPRESS;Initial Catalog=DB_Naved_Test;Integrated Security=True"; SqlConnection con = new SqlConnection(str); string query =...

Migrating Custom .NET ORM to Entity Frame / Dapper

c#,mysql,asp.net-web-api,migration,dapper
I've inherited a project that is massive in scale, and a bit of a labyrinth. The traffic is substantial enough to want to optimize the data access, so I've began converting some WCF services that are invoked by javascript to Web API. Unfortunately, the database's primary keys (not auto incrementing)...

Pass field name in dapper query

c#,dapper
I'm creating a function where I check if a maintenance day is checked in the database. Each Column is Maintenance + DayName (MaintenanceSunday, MaintenanceMonday, etc.). It appears that anytime you pass in an object, it wants to take the value of what is being checked and not "inject" the string....

Dapper, MS Access, Integers and “no value given for one or more required parameters”

c#,ms-access,visual-studio-2012,oledb,dapper
I keep getting the error "no value given for one or more required parameters" on the third attempt to insert in the code below. The first two attempts work fine. I'm running in .NET 4.0, against MS Access in VS 2012. And this problem appears to be consistent whether I'm...

How to put objects into a dictionary using Dapper in C#?

c#,sql-server,dictionary,dapper
I have a dictionary like the following: Dictionary<string,SP> dict; that contains a string and a SP object. I would like to do the following dict = conn.Query("SELECT routine_name,created,modified FROM PROCEDURES").toDictionary ( row => (string)row.Routine_Name, row => new SP (Name=row.Routine_Name,Created=row.created,Modified=row.modified)); The above code is not working. How can I create a...

Advanced cascade delete

c#,sql,sql-server,tsql,dapper
I have a very simple database whose schema is defined as follows: CREATE TABLE dbo.Tags ( TagName NVARCHAR(100) PRIMARY KEY ); CREATE TABLE dbo.Posts ( PostSlug NVARCHAR(100) PRIMARY KEY, Title NVARCHAR(100) NOT NULL ); CREATE TABLE dbo.PostTagJunction ( PostSlug NVARCHAR(100), TagName NVARCHAR(100) PRIMARY KEY (PostSlug, TagName), FOREIGN KEY (PostSlug) REFERENCES...

model isn't working as expected C#

c#,model,mapping,dapper
My model is getting data I need, but I'm not sure how to organize it in the way I need. I have it where the model pulls a team, and a player. The issue is when mapping my data to the model it gives me duplicate teams, and doesn't allow...

How can I use Dapper with a SELECT stored procedure containing an INNER JOIN between two tables?

c#,.net,dapper
I am experimenting with Dapper for the first time. I have two tables: Films and Ratings. CREATE TABLE [dbo].[Films] ( [Id] INT NOT NULL PRIMARY KEY, [Title] VARCHAR(250) NOT NULL, [Genre] VARCHAR(50) NOT NULL, [RatingId] INT NOT NULL, CONSTRAINT [FK_Films_To_Ratings] FOREIGN KEY (RatingId) REFERENCES Ratings(Id) ) CREATE TABLE [dbo].[Ratings] (...

Using default generic values in C#

c#,ado.net,dapper
I have some code written in C#. I am trying to write some generic code that I can reuse. My actual code is more complicated. However, the code is question looks like the following: public async Task<T> ExecuteQueryAsync<T>(string sql) { var results = default(T); using (var database = new SqlConnection("[ConnectionString]"))...

Cast dynamic dapper query

c#,dapper
Im trying to convert a dynamic query from dapper to IDictionary const string sql = @"SELECT Name, Street FROM Contact"; dynamic query = null; using (var cn = Connection) { query = cn.Query<dynamic>(sql); } var rows = query as IDictionary<string, object>; foreach (var row in rows) { // Getting values...

Dapper > I cannot retrieve object with child object

dapper
I have the following Quote and Share classes: public class Quote { public Quote(string ticker, string name, decimal lastPrice) { this.Ticker = ticker; this.Name = name; this.LastPrice = lastPrice; } public string Ticker { get; private set; } public string Name { get; private set; } public decimal LastPrice {...

Stored Procedure using Dapper in MVC 4

c#,asp.net,model-view-controller,dapper
I am trying to do CRUD operation in MVC using Dapper and stored procedure but I am not able to return result from model to controller due to conversion error which I am not able to solve. Please can anyone help what should I return as my result This is...

Dapper: What's the difference between these two pieces of code?

c#,dapper
I've registered a custom type handler for Dapper to Json serialize a string. This works as expected. However, whilst coding, I discovered two pieces of code after refactoring, the latter one which didn't trigger the datatype handler, but should in my opinion, so what's the difference? First the code that...

Using Sql, how can I hydrate child objects from within a single Query?

c#,sql,entity-framework,tsql,dapper
I'm using Dapper, but I think this applies to general SQL: I have the following: var dapperQuery = "select * from ( select * from [User] where " + "AccountDisabled <> 1 and " + "Rate <= @maxRate and " + "(datediff(day, Birthdate, @today) / 365) between @minage and @maxage";...

Ef and Dapper.net in one solution

entity-framework,dapper
Is there a reason why I couldn't use both EF and Dapper.NET in my solution?? EF like to use due to the flexibility of the programming , but when I need to select several large amounts of data then used the Dapper. Can it lead to any conflict???

How can I find a second property with a duplicate name from a dynamic object?

dapper
Using Dapper I have a result set which contains two SQL columns with the same name. How do I read the values? Both the User and Skill table have a column called Name. An example of my code: var query = _connection.Query(@" select u.*, s.* from [User] u left join...

Dapper using ODBC store procedure Input parm always promt @XXX was not supplied

odbc,dapper
I need help from All Dapper master. I have been learning using Dapper since one month ago, but I have error when executing query using ODBC SP. The code originally was written by someone(DapperExample) but not using ODBC, thanks to the writer I forgot your name. My SP: CREATE PROCEDURE...

Why does this dapper query return null?

c#,mysql,asp.net-mvc-3,dapper
I have a mysql statement that I am passing to the dapper query method and it is returning a null object. I have created a POCO class to hold the returned result. I tested the query directly through a sql editor and it returned a result. Here is the code:...

Should dapper use a “using” statement?

c#,dapper,micro-orm
I have seen examples where someone is doing: IDbConnection db = new MySqlConnection(conn); var people = db.Query<People>("SELECT * FROM PEOPLE").ToList(); or is the above a bad practice and should all queries be put in using statements like so: using (var db = new MySqlConnection(conn)) { var people = db.Query<People>("SELECT *...

Map Stored procedure result to object inside an object

c#,sql,sql-server,stored-procedures,dapper
If i have a Person class which have Dog class property : public class Person{ public string Name {get;set;} public Dog Doggie {get;set;} } On a single SP call i want to populate both dog object and person object, but i cant figure out how to do that. CREATE PROCEDURE...

named parameters in sp_executesql

sql-server,tsql,dapper,sp-executesql
is there any way that you can call sp_executesql with parameters that don't depend in the order they are defined in the store? the same query with exec works well, and if you have the same order it also works well, but it's a pain having to match the parameter...

Code first approach in dapper [closed]

c#,entity-framework,dapper
I got an urgent requirement to complete an application. My personal preference is to go with ORM's for this purpose. I haven't used any ORM's yet and I have little knowledge about EntityFramework. Recently I heard of Dapper and have thought of using it. My question is: Is it possible...

How to use Dapper.QueryMultiple with Sqlite

c#,.net,sqlite,dapper
The Dapper documentation states you can send off multiple queries at once and iterate over the results using the QueryMultiple method like so: var sql = @" select * from foo where id = @paramname select * from bar where id = @paramname"; conn.QueryMultiple(sql, new {paramname = paramval}); It would...

C# - Passing parameter to stored procedure and return IEnumerable

c#,sql-server,stored-procedures,dapper
can I directly pass the parameter in the query as shown below? There is error so anyone could help? public IEnumerable ListTop10countries(string direction) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCON"].ToString())) { var list = con.Query<OutputCountries>("Usp_GetTop10", direction).AsEnumerable(); return list; } } Error: An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but...

Dapper throws “Invalid type owner for DynamicMethod.”

c#,dapper
So I'm trying to use Dapper.net and I'm liking it. What I'm not liking is when I try to batch-insert entities and I get the following error thrown: Invalid type owner for DynamicMethod. at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility,...

Mapping an non-primitive object with Dapper

orm,dapper
I have the following class public class Point { public long Id { get; set; } public Address Address { get; set; } } I am attempting to have Dapper correctly map the Address data. var points = this._db.Query<Point>("select * from Points").ToList(); My table schema is as follows: Is there...