You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe that InMemory should not enforce relational behavior when invoking Include on an invalid navigational property.
One of the main reasons is that InMemory doesn't enforce relational behavior when adding entities, so it should also exhibit the same behavior when reading entities.
Given the sample below, ctx.Posts.Include(p => p.Blog) should have the same behavior as ctx.Posts given a Post entity with no Blog.
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using Xunit;
public class Tests
{
[Fact]
public void Add_Post_with_no_Blog_is_ok()
{
var options = new DbContextOptionsBuilder<Context>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.Options;
using (var ctx = new Context(options))
{
ctx.Add(new Post());
ctx.SaveChanges();
}
using(var ctx= new Context(options))
{
var post = ctx.Posts.Single();
Assert.NotNull(post);
}
}
[Fact]
public void Read_Post_Include_Blog_when_no_Blog_is_not_ok()
{
var options = new DbContextOptionsBuilder<Context>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.Options;
using (var ctx = new Context(options))
{
ctx.Add(new Post());
ctx.SaveChanges();
}
using (var ctx = new Context(options))
{
var post = ctx.Posts.Include(p => p.Blog).Single();
Assert.NotNull(post);
}
}
}
public class Context : DbContext
{
public Context(DbContextOptions<Context> options) : base(options) { }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
public class Blog
{
public int BlogId { get; set; }
}
I also read #2166 and #9470 which seem to be related but I'm confused whether this was already decided or not.
Further technical details
EF Core version: 2.1.2
Database Provider: Microsoft.EntityFrameworkCore.InMemory
Operating system: Win7
IDE: Visual Studio 2017 15.4
The text was updated successfully, but these errors were encountered:
@gojanpaolo We intend to maintain the semantics of FK relationships in the in-memory database, including at some point adding constraint checking. However, we discussed this in triage and we believe that it would be useful to specify an "unconstrained" FK relationship, whether targeting in-memory or relational database. I have opened #13146 to track this.
I believe that InMemory should not enforce relational behavior when invoking Include on an invalid navigational property.
One of the main reasons is that InMemory doesn't enforce relational behavior when adding entities, so it should also exhibit the same behavior when reading entities.
Given the sample below,
ctx.Posts.Include(p => p.Blog)
should have the same behavior asctx.Posts
given aPost
entity with noBlog
.I also read #2166 and #9470 which seem to be related but I'm confused whether this was already decided or not.
Further technical details
EF Core version: 2.1.2
Database Provider: Microsoft.EntityFrameworkCore.InMemory
Operating system: Win7
IDE: Visual Studio 2017 15.4
The text was updated successfully, but these errors were encountered: