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

Shadow property naming docs are incorrect #6655

Closed
mikebrind opened this issue Sep 30, 2016 · 4 comments
Closed

Shadow property naming docs are incorrect #6655

mikebrind opened this issue Sep 30, 2016 · 4 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@mikebrind
Copy link

Steps to reproduce

Create the model as detailed in the documentation on shadow properties here: https://ef.readthedocs.io/en/latest/modeling/shadow-properties.html#conventions

class MyContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }
}

public class Blog
{
    public int BlogId { get; set; }
    public string Url { get; set; }

    public List<Post> Posts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }

    public Blog Blog { get; set; }
}

Then add a migration.

The issue

The database column and therefore the shadow property for the foreign key in the Posts table is named 'BlogId' instead of BlogBlogId contrary to the documentation:

migrationBuilder.CreateTable(
    name: "Posts",
    columns: table => new
    {
        PostId = table.Column<int>(nullable: false)
            .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
        BlogId = table.Column<int>(nullable: true),
        Content = table.Column<string>(nullable: true),
        Title = table.Column<string>(nullable: true)
    },

Is the bug in the documentation or the framework?

@smitpatel
Copy link
Contributor

@mikebrind - Which version of EF are you using?
In #6317 , the behavior was changed. If the PK property name has navigation/entitytype name as prefix then prefix would be removed. Hence shadow property is created with name BlogId dropping prefix Blog from navigation name. Though this change is in dev branch and not released to public yet. And documentation refers to public bits therefore there is difference.

For Triage: This could be a breaking change.

@mikebrind
Copy link
Author

mikebrind commented Oct 1, 2016

@smitpatel I'm using 1.0.0:

"dependencies": {
    "Microsoft.Extensions.Configuration": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    }
  },

@rowanmiller
Copy link
Contributor

@smitpatel to verify if we changed the naming between 1.0 and 1.1

@smitpatel
Copy link
Contributor

smitpatel commented Oct 3, 2016

@rowanmiller - RTM generates BlogId so documentation error. Behaviour is consistent between 1.0 & 1.1.

@smitpatel smitpatel assigned rowanmiller and unassigned smitpatel Oct 3, 2016
rowanmiller added a commit to dotnet/EntityFramework.Docs that referenced this issue Oct 6, 2016
@rowanmiller rowanmiller changed the title Shadow property naming not working as documented Shadow property naming docs are incorrect Oct 7, 2016
@rowanmiller rowanmiller added type-bug closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed type-investigation labels Oct 7, 2016
@rowanmiller rowanmiller modified the milestones: 1.1.0-preview1, 1.1.0 Oct 7, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

No branches or pull requests

4 participants