c# ef6 sqlite The store type rowversion could not be found in the SQLite provider manifest
The error "The store type 'rowversion' could not be found in the SQLite provider manifest" occurs when using the rowversion data type in an Entity Framework 6 application with SQLite as the database provider.
SQLite does not have a built-in equivalent for the rowversion data type, which is commonly used for optimistic concurrency in SQL Server.
To resolve this issue, you can modify your code to use a different data type that is supported by SQLite. One possible alternative is to use the integer data type with AUTOINCREMENT attribute, which can be used to achieve similar functionality.
Here's an example of how you can modify your code:
- Change the property type from
rowversiontoint:
public class MyEntity
{
public int Version { get; set; }
// other properties
}
- Add the
AUTOINCREMENTattribute to the property configuration in yourDbConfigurationclass:
public class MyDbConfiguration : DbConfiguration
{
public MyDbConfiguration()
{
SetProviderServices("System.Data.SQLite",
(DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
SetDefaultConnectionFactory(new SQLiteConnectionFactory());
SetManifestTokenResolver(new SQLiteManifestTokenResolver());
// Configure the property with AUTOINCREMENT attribute
SetColumnAnnotationConvention<PropertyInfo>(
"System.Data.SQLite", "Autoincrement", (prop, attributes) =>
attributes.Single().NewValue = "True");
}
}
Make sure to update the MyDbConfiguration class name and the property name accordingly.
By making these changes, you should be able to use the int data type with AUTOINCREMENT attribute as a substitute for the rowversion data type in SQLite.
原文地址: https://www.cveoy.top/t/topic/i5kB 著作权归作者所有。请勿转载和采集!