Beispiel #1
0
        public void FailsWithSqlite()
        {
            // Arrange
            var logger     = _loggerFactory.CreateLogger <WeatherForecastController>();
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            using var command   = connection.CreateCommand();
            command.CommandText = "PRAGMA FOREIGN_KEYS=OFF";
            command.ExecuteNonQuery();
            var dbContextOptionsWithSqlite = new DbContextOptionsBuilder <BloggingContext>()
                                             .UseSqlite(connection)
                                             .UseLoggerFactory(_loggerFactory)
                                             .Options;
            var dbContext = new BloggingContext(dbContextOptionsWithSqlite);

            PrePopulateDatabase(dbContext);
            var controllerWithSqlite = new WeatherForecastController(logger, dbContext);

            // Act
            // Fails with 'The LINQ expression ... could not be translated'
            // because Sqlite can't perform greater than / less than comparisons on DateTimeOffsets (because it stores it as a string)
            controllerWithSqlite
            .Invoking(x => x.Get())
            .Should()
            .ThrowExactly <System.InvalidOperationException>()
            .And.Message.Should().StartWith("The LINQ expression 'DbSet<Post>()");
            //The LINQ expression 'DbSet<Post>()
            //    .Where(p0 => EF.Property<Nullable<int>>(EntityShaperExpression:
            //        EntityType: Blog
            //        ValueBufferExpression:
            //            ProjectionBindingExpression: EmptyProjectionMember
            //        IsNullable: False
            //    , "BlogId") != null && object.Equals(
            //        objA: (object)EF.Property<Nullable<int>>(EntityShaperExpression:
            //            EntityType: Blog
            //            ValueBufferExpression:
            //                ProjectionBindingExpression: EmptyProjectionMember
            //            IsNullable: False
            //        , ""BlogId""),
            //        objB: (object)EF.Property<Nullable<int>>(p0, "BlogId")))
            //    .Where(p0 => p0.PublicationDateTime > DateTimeOffset.Now.AddDays(-5))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
        }