How to do multiple insert as well update by using dapper .net? - c#

How to do multiple insert (50000 record) as well update using dapper .net ?
Is it possible to use SqlBulkCopy to achieve this? If yes then how?
Is there any best way to implement multiple hierarchical insert or update using Dapper.net?
Technologies : C#, SQL Server 2012, Dapper.net

If you just want to insert: SqlBulkCopy should be fine; if you want an "upsert", I suggest table-valued-parameters (which dapper supports) and the merge t-sql operation
Dapper just simplifies ado.net; if you think of a way to do it in ado.net, dapper can probably make it easier for you; however, it sounds like multiple TVPs might suffice

If you are mean to OK and able to segregate insert and update entities separately then I would suggest to use Dapper.Contrib library provided by Dapper.Net guys themselves. It is available via nuget. It has worked very efficiently for my project.
Here is the link to their Github project page.

Related

The equivalent way of 'OracleCommand.ArrayBindCount' in npgsql

I'm porting my old project. It previously use Oracle.DataAccess.Client library to access with oracle database.
Now, I want to use Npgsql library to access with Postgresql database. So I need to porting the old c# code which use Oracle library method. For example, the old code use OracleCommand.ArrayBindCount property to insert multi rows at once.
But I do not see the similar method or property to do the same thing.
I want to know if there're similar ways to achieve it.
No, there's nothing like ArrayBindCount in Npgsql/PostgreSQL.
However, you can batch two (or more) INSERT statements in the same CommandText (delimited by semicolons) and have all the parameters for all statements on that command. This would execute efficiently as a single batch.
For really efficient bulk insert, use COPY which is by far the fastest.
You also can refer below post.
Does PostgreSQL have the equivalent of an Oracle ArrayBind?

How to use SQL Bulk Copy with Dapper .Net ?

I am working with Dapper .net for Bulk insert operation in SQL Tables. I am thinking to user SQKBulk copy with Dapper .Net but don't have any experience How to use SqlbulkCopy with Dapper .Net
your help is Highly appreciated
It is not good idea to use dapper for bulk insert, because there it will not fast. The better case for this is use of SqlBulkCopy class. But if you want use Dapper for bulk insert, you can find solution here.

Difference between Native SQL and Entity SQL

I have gone through an article of using EntityConnection, EntityCommands for executing Entity sql queries. But I was unable to understand that Why are we using Entity sql? Why not directly using the Classes and objects for processing CRUD operations on database?
Or If we want to execute sql queries then why we are using Entity Sql , why not directly Ado.net ?
Is there any performance difference or something else?
I have already gone through the page http://msdn.microsoft.com/en-us/library/bb738573.aspx. But I want answer in a more simpler way. Can you please answer me?
Thanks
Why not directly using the Classes and objects for processing CRUD operations on database?
That is (should be) the way for almost all operations. But sometimes there is a need for accessing the db more directly and precisely.
If we want to execute sql queries then why we are using Entity Sql , why not directly Ado.net ?
E-SQL will still let you work with entities (instead of Rows). This is much easier and more powerful, consider inheritance for example.
E-SQL is also supposed to be independent of the actual database, ie the same for Oracle etc. I have no experience with this yet.
Is there any performance difference or something else?
It can be used to improve performance, yes. But not automatically.
The main difference
SQL is database dependent query language working on storage (relational) objects - tables / rows
ESQL is database independent query language working on conceptual (EDMX) objects - entities
ESQL was created prior to LINQ. In some scenarios ESQL offers more functionality than LINQ.

How to batch insert lots of rows using Enterprise Library DAAB?

How can I execute 1000s of INSERT queries using Enterprise Library DAAB? That is to say how can I insert lots of rows into a table using DAAB all at once efficiently? And without using a for-loop. Thanks.
Unfortunately, I'm not sure you can do that using the Enterprise Library DAAB without extending it. As an alternative you can use SqlBulkCopy.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx
EDIT
The Oracle Data Provider for .NET (ODP.NET) supports this via the Array Binding feature.
http://www.oracle.com/technetwork/issue-archive/2009/09-sep/o59odpnet-085168.html

one Library for multiDatabases

Im developing a windows forms application using C# 4.0 and that application is going to target different database engines like SQL, MySQL and Oracle i was wondering if there is a library that can talk to all the three engines instead of implementing my own layers for every one.
thanks in advance.
You could use an ORM tool; I like NHibernate But there are many more: see a list at wikipedia.
The problem is if you want to do anything remotely advanced (date arithmatic, generate primary keys, get the id of the last inserted record, pivot a table , use RANGE construct etc.) then both databases use completely different syntax.
The best solution (in the java world at least is either Ibatis or Hibernate) I know there is a .NET version of Hibernate I am not sure about Ibatis.
These libraries insulate your program from the various SQL dialects and provide a common API independent of the underlying database.
If you use the classes in System.Data.Common you can make your code database independent:
Writing Provider Independent Code in ADO.NET
I don't know C#, but I know it will have a library for ODBC.
It looks like MS has one here.
It's old, but actually it does the job just fine. Virtually every DB in existence provides an ODBC driver.
Checkout DbLinq.
DbLinq is THE LINQ provider that allows to use common databases with
an API close to Linq to SQL. It currently supports (by order of
appearance): MySQL, Oracle, PostgreSQL, SQLite, Ingres, Firebird...
And still SQL Server.

Categories