Hi
I try to insert Arabic number like :(۳۹۹۳) in SQLServer and type column nvarchar with ORMLite but it saved like :(???)!!
Any help Please?
Hi
I try to insert Arabic number like :(۳۹۹۳) in SQLServer and type column nvarchar with ORMLite but it saved like :(???)!!
Any help Please?
Please provide a minimal code example that we can run locally to repro the issue.
I have an object contains a string fields when my string fildes contains arabic number like :(۳۹۹۳) it insert as ???
myClass is:
public int Id{ get; set; }
public string filed1{ get; set; }
public string filed2{ get; set; }
my code :
myclass myobject = new myclass();
myobject.filed1=“۳۹۹۳”;
DB.Save(myobject,false);
Please note we need a minimal reproducible example we can run locally, i.e. including any configuration used, the code provided isn’t close to being able to compile or run. Please provide stand-alone reproducible examples when reporting issues in future.
You need to set unicode to save unicode strings, configure this at the start of your App after initializing your OrmLiteConnectionFactory
:
var dbFactory = new OrmLiteConnectionFactory(connStr, SqlServer2012Dialect.Provider);
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = true;
my Code is very simple:
public bookUpdate(Book updateBook)
{
updateBook.bookName="۳۹۹۳";
DB.Save(updateBook , false);
return updateCase;
}
and I have add the configurations line you reply it to me so it will be as :
public bookUpdate(Book updateBook)
{
updateBook .bookName="۳۹۹۳";
var dbFactory = new OrmLiteConnectionFactory(connStr, SqlServer2012Dialect.Provider);
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = true;
DB.Save(updateBook , false);
return updateCase;
}
public class Book
{
public int Id { get; set; }
public string bookName { get; set; }
public string bookAuthor { get; set; }
}
Don’t configure the OrmLiteConnectionFactory
at runtime, it needs to only be setup once at the start of your App before you use OrmLite.
var dbFactory = new OrmLiteConnectionFactory(connStr, SqlServer2012Dialect.Provider);
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = true;
When using OrmLite you will be resolving an DB connection from the factory, e.g:
using (var db = dbFactory.Open())
{
}
Or if you’re using an IOC:
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(connStr, SqlServer2012Dialect.Provider));
using (var db = container.TryResolve<IDbConnectionFactory>().Open())
{
}
Normally the IDbConnectionFactory
is injected, e.g. if you’re using ServiceStack you can use Db
directly which will resolve the DB Connection from the IOC behind-the-scenes:
Db.Save(updateBook);
Please take the time to read the OrmLite docs.
Thank you very much …It is working fine now
Can I find docs that explain to me differences between SqlServerDialect.Provider and SqlServer2012Dialect.Provider and SqlServer2015Dialect.Provider and SqlServer2017Dialect.Provider?
Use the one that best matches your SQL Server version, for SQL Server 2008 or lower use SqlServer2008Dialect.Provider
.