Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ad-hoc type with property that looks like collection navigation does not fail model validation #30056

Closed
ajcvickers opened this issue Jan 13, 2023 · 2 comments · Fixed by #30211
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ajcvickers
Copy link
Member

Instead, it is just ignored. Reference navigations will cause validation to fail.

Code:

public class Blog
{
    public string? Name { get; set; }
    public virtual List<Post> Posts { get; } = new();
}

public class Post
{
    public string? Title { get; set; }
}

public class SomeDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow")
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Blog>().HasNoKey();
        modelBuilder.Entity<Post>().HasNoKey();
    }
}

public class Program
{
    public static async Task Main()
    {
        using (var context = new SomeDbContext())
        {
             await context.Database.EnsureDeletedAsync();
             await context.Database.EnsureCreatedAsync();

             await context.SaveChangesAsync();
        }
    }
}

Model:

Model: 
  EntityType: Blog Keyless
    Properties: 
      Name (string)
  EntityType: Post Keyless
    Properties: 
      Title (string)
@ajcvickers
Copy link
Member Author

This is apparently by design:

We should decide if this is also okay for ad-hoc types, which are always keyless.

@ajcvickers
Copy link
Member Author

Note from triage: leave behavior unchanged for normal keyless types, but throw in validation for ad-hoc types.

@ajcvickers ajcvickers added this to the 8.0.0 milestone Jan 19, 2023
@ajcvickers ajcvickers changed the title Keyless type with property that looks like collection navigation does not fail model validation Ad-hoc type with property that looks like collection navigation does not fail model validation Feb 4, 2023
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Feb 4, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0, 8.0.0-preview2 Feb 16, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-preview2, 8.0.0 Nov 14, 2023
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant