When I try to save an entity with its reference using db.save(book,true)
the book entity saved correct but without it is list of reference and it is give exception as following :
could not found Dialect
Boolean ServiceStack.OrmLite.OrmLiteDialectProviderBase`1.ShouldSkipInsert(ServiceStack.OrmLite.FieldDefinition)’.
my code :
public class Book
{
[PrimaryKey]
[AutoIncrement]
public int Id { get; set; }
public List<author> authors {get; set;}
}
public class Author
{
[PrimaryKey]
[AutoIncrement]
public int Id { get; set; }
public string name {get; set;}
}
when the author list have value it give me error
I create factory once in my repository :
istatic UnitOfWork()
{
Obj = new UnitOfWork(CnnStr);
}
public UnitOfWork(string connectionString)
{
if(DbFactory == null)
{
DbFactory = new OrmLiteConnectionFactory(CnnStr, SqlServer2016Dialect.Provider);
OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode = true;
}
DB = DbFactory.OpenDbConnection();
}
This is still not a runnable example. The issue needs to be a stand alone reproducible example that just needs a connection string to run either as a Console App or unit test. If you want to submit a Web App example, create a project on GitHub that can be checked out, built and run without any additional code or build steps. If it requires more than swapping a connection string and installing NuGet packages to run it’s not a stand alone example.
With that said, your DbFactory should be a singleton instance created in your AppStartup and used for all DB connections. DB connections should be disposed of immediately after usage, not passed around unless you’re certain it’s never accessed by more than 1 thread and disposed after usage. Your OrmLite models should be POCOs and not contain data access logic. Either way I can’t tell you exactly what you’re doing wrong without a stand alone reproducible example.
Calling dbFactory.Open() returns an Open ADO.NET connection, it needs to be disposed after usage as normal, typically this is done in a using statement, e.g
using (var db = dbFactory.Open()) {
}
Or could be disposed by your IOC if it’s configured to do so at the end of the Request, either way it needs to be disposed of after usage or the end of a request and shouldn’t be reused over multiple requests as it’s ADO.NET connections aren’t ThreadSafe.