OrmLite, SQLServer: Identity not updated

I have a repository for create, edit, delete table below.

public class OrmLiteCompanyRepository : OrmLiteCompanyRepository<Company, CompanySetting, CompanyView>
    public OrmLiteCompanyRepository(IDbConnectionFactory dbFactory) : base(dbFactory) { }
    public OrmLiteCompanyRepository(IDbConnectionFactory dbFactory, string namedConnnection = null)
        : base(dbFactory, namedConnnection) { }

public class OrmLiteCompanyRepository<TCompany, TCompanySetting, TCompanyView> : OrmLiteBaseRepository, ICompanyRepository, IRequiresSchema, IClearable

     where TCompany : class, ICompany
    where TCompanySetting : class, ICompanySetting
    where TCompanyView : class, ICompanyView

Company Type:

public class Company : ICompany
    public int Id { get; set; }
    public int Type { get; set; }
    public string Code { get; set; }

Where create new company, i call:


BUT when i retrieve Id then newCompany.Id == 1 always
It’s error when i upgrade to SS 4.5.10 and 4.5.12.

Any bug here?

OrmLite’s Save works as expected but when using OrmLite APIs it needs access to the concrete type in order to be able to access the table metadata. So first check that (TCompany) is the concrete Company table and not a base class or interface.

The next thing to check is that you’re really inserting new records and not just updating the same record which a value of non 0 would seem to indicate. i.e. db.Save() only populates the record with the RDBMS’s AutoIncrement Id if it’s inserting a new record, if Id is already set to 1 then it’s likely db.Save() is only updating an existing record, not inserting a new one.

If you’ve confirmed it’s inserting a record and not populating the Id please add a stand-alone repro on Gistlyn which we can run to see the issue.

Please check gist

The example is full of build errors so I think you forgot to save your latest version. Secondly there’s no code that’s run that shows the issue, It’s just a dump of classes? If you haven’t saved your latest version please save it and make sure I can run the code.

I’ve added this code at the end:

var repo = new OrmLiteCompanyRepository(dbFactory);

var newCompany1 = new Company();

var newCompany2 = new Company();

var allCompanies = db.Select<Company>();

And everything’s working as expected, I see 2 rows in the table and each company is populated with the Id.

If there is still an issue please update the example so I can run it to see exactly what the issue is .

OK, i just have detected my issue, it’s affected by trigger after insert new company record.
When i disable trigger then work right.
How do i get correct if using OrmLite and don’t care table have or not have trigger?

OrmLite populates the Id with the AutoIncrementing Id returned by the RDBMS, if your trigger is interfering with it, don’t use them.