I have some problem for insert use Dapper.Contrib.I have class like below
```c#
public class Company
{
public int Id { get; set; } = 1;
public string CompanyName { get; set; }
}
My table like below picture
![image](https://cloud.githubusercontent.com/assets/5998113/26793228/da06509c-4a4f-11e7-8d89-5d8c63580cde.png)
If i am using sql to insert that is ok.If i use insert to mssql also success but if i use oracle that is wrong.I want show code to below.If You need deep details that must tell me.
```c#
public class Company
{
public int Id { get; set; } = 1;
public string CompanyName { get; set; }
}
public IDbConnection GetConnection
{
get
{
string connString = "Data source=localhost/book;User id=C##ANSON;Password=1234;";
var conn = new OracleConnection(connString);
return conn;
}
}
public async Task<IHttpActionResult> Post()
{
var companys = new List<Company>();
for (int i = 0; i < 5; i++)
{
companys.Add(new Company
{
CompanyName = $"company{i}"
});
}
using (TransactionScope scope = new TransactionScope())
{
using (var con = GetConnection)
{
//con.Execute("insert into company (companyname) values (:companyname)", companys.Select(x => new CompanyDto { CompanyName = x.CompanyName }));
//if use above that is success.but if use below that will occurred ORA-00928
con.Insert(companys);
scope.Complete();
return Ok();
}
}
}
Same problem here:
{
SqlMapper.AddTypeMap(typeof(DateTimeOffset), System.Data.DbType.DateTime);
_oracleConnection.Open();
return (_oracleConnection.Insert<TEntity>(entityToInsert));
}
Part of the entity:
public class UserItem2
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("USUARIO_ID")]
public int USUARIO_ID { get; set; }
[StringLength(100)]
[Column("NOMBRE_TX")]
[Required]
public string NOMBRE_TX { get; set; }
Also facing the same issue. Any update yet?
Dapper/Dapper.Contrib/SqlMapperExtensions.cs
GetFormatter method use AdapterDictionary in insert,update,delete methods.
private static readonly Dictionary<string, ISqlAdapter> AdapterDictionary
= new Dictionary<string, ISqlAdapter>
{
["sqlconnection"] = new SqlServerAdapter(),
["sqlceconnection"] = new SqlCeServerAdapter(),
["npgsqlconnection"] = new PostgresAdapter(),
["sqliteconnection"] = new SQLiteAdapter(),
["mysqlconnection"] = new MySqlAdapter(),
["fbconnection"] = new FbAdapter()
};
guys, where is OracleDataAdapter?
0001-add-custom-AdapterDictionary.patch.zip
Please add this patch to extentions in Dapper/Dapper.Contrib/SqlMapperExtensions.cs!
I need it to add my own Oracle adapter.
It's possible to add it by Invoke method but this is ugly solution.
How do I use this patch?
git apply --stat 0001-add-custom-AdapterDictionary.patch
It will be available to add custom adapter when this patch would be applied.
new method AddAdapter at SqlMapperExtensions
Custom adapter can be made based on common (default) adapter SqlServerAdapter.
workaround is to use reflection to get private member:
var adapters = (Dictionary<string, ISqlAdapter>) typeof(SqlMapperExtensions)
.GetField("AdapterDictionary", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)?.GetValue(null);
var connectionType = connection.GetType().Name.ToLower();
if (adapters != null && !adapters.ContainsKey(connectionType))
{
adapters?.Add(connectionType, new OracleServerAdapter());
}
OracleServerAdapter is a class based on ISqlAdapter interface.
have working Oracle Adapter in my fork (https://github.com/P0ntiuS/Dapper/commits/master)
Would it be possible to include this in the official Dapper.Contrib release?
@NickCraver @mgravell - Would it be possible to have this added to the official repo? Working in a tightly-controlled environment and can only use Nuget.
https://github.com/StackExchange/Dapper/issues/796#issuecomment-375695295
我在Dapper.Contrib的基础上扩展了OracleAdapter (https://github.com/EminemJK/Banana)
Still not working on oracle...
Most helpful comment
Would it be possible to include this in the official Dapper.Contrib release?