Sto creando database SQLite In Memory per il test delle unità:
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
try
{
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseSqlite(connection)
.Options;
// Create the schema in the database
using (var context = new BloggingContext(options))
{
context.Database.EnsureCreated();
}
// Run the test against one instance of the context
using (var context = new BloggingContext(options))
{
var service = new BlogService(context);
service.Add("http://sample.com");
}
// Use a separate instance of the context to verify correct data was saved to database
using (var context = new BloggingContext(options))
{
Assert.AreEqual(1, context.Blogs.Count());
Assert.AreEqual("http://sample.com", context.Blogs.Single().Url);
}
}
context.Database.EnsureCreated (); fallisce con eccezione: Messaggio: Microsoft.Data.Sqlite.SqliteException: SQLite Errore 1: 'near "MAX": errore di sintassi'.
C'è un problema di github che dice: Il problema qui è varchar (max) è il tipo specifico di SqlServer. Lo scaffolding non deve aggiungerlo come tipo relazionale che viene passato alla migrazione in altri provider che sono inclini a generare sql non valido durante la migrazione.
Ma come posso usare SQLite in memoria per i test unitari se il mio database contiene molte colonne varchar (max)?