Could not found DialectProvider

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();

        }

and update code :

UnitOfWork.Obj.DB.Save(book, true);

This issue is not reproducible from this example. Please create a stand-alone example on GitHub that I can run locally to reproduce the issue.

I have edit my code . I think now it reproducible :blush:

Please provide a complete stand-alone example that can be run locally as requested.

If you don’t want to create a GitHub project, you can create a complete stand-alone Console App in a Gist:

I should only need to be able to change the connectionString to be able to run the example.

I hope this will be helpful :smile:

be note the db is save the parent correct but give exception if the list not null

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.

what I understand DB connections is disposed immediately after usage from ormLite …isn’t?

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.

if I make the config :

DbFactory.AutoDisposeConnection = true;

is not enough ?

I try to test my case on
https://gistlyn.com/?gist=840bc7f09292ad5753d07cef6063893e&collection=991db51e44674ad01d3d318b24cf0934

and it is working fine !

I think the problem in dialectprovider

Try swapping it with SqlServer2012Dialect.Provider and let me know if it resolves the issue.

think for your help :smile:

It is working fine now

I want to ask what is the different between :

DbFactory.AutoDisposeConnection = true
and
DbFactory.AutoDisposeConnection = false

AutoDisposeConnection is only relevant for the In Memory SQLite provider, i.e. :memory:. Other RDBMS’s shouldn’t use it.