Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Indexed non-AutoProperty properties accessibility error #101

Closed
RuiAlias opened this issue Sep 30, 2019 · 2 comments
Closed

Indexed non-AutoProperty properties accessibility error #101

RuiAlias opened this issue Sep 30, 2019 · 2 comments
Labels
bug Confirmed bug released Issue is resolved in a current release
Milestone

Comments

@RuiAlias
Copy link
Contributor

Hi,

Creating a property with AutoProperty set to false and Indexed set to true generates code with a compile-time error.

image

   public partial class Country
   {
...
      /// <summary>
      /// Backing field for ISO
      /// </summary>
      protected string _ISO;
modelBuilder.Entity<global::BottomUp.Model.Country>().HasIndex(t => t._ISO)
                     .IsUnique();

The error is CS0122 'Country._ISO' is inaccessible due to its protection level.

Should this combination not be possible or is it a bug?

@msawczyn msawczyn added bug Confirmed bug pending release Issue is resolved in the current codebase, will be published with the next release labels Sep 30, 2019
@msawczyn msawczyn added this to the 1.3.0.6 milestone Sep 30, 2019
@msawczyn
Copy link
Owner

Please take a look at the 1.3.0.6 pre-release. Look forward to your feedback.

@msawczyn msawczyn added released Issue is resolved in a current release and removed pending release Issue is resolved in the current codebase, will be published with the next release labels Oct 1, 2019
@RuiAlias
Copy link
Contributor Author

RuiAlias commented Oct 1, 2019

Thanks for the quick replies and fixes! There are no more compilation errors.

I think there's another problem now. Each one of these (Indexed and non-AutoProperty) properties is generating two database fields. Is this necessary?

For example, an entity Currency with 3 properties: Code as primary key (Manual Indentity Type) and Name and Symbol are Indexed and non-AutoProperty, generates a table with 5 fields, Code, Name, Symbol, _Name and _Symbol.

image

         modelBuilder.Entity<global::BottomUp.Model.Currency>()
                     .ToTable("Currency")
                     .HasKey(t => t.Code);
         modelBuilder.Entity<global::BottomUp.Model.Currency>().HasIndex("_Name")
                     .IsUnique();
         modelBuilder.Entity<global::BottomUp.Model.Currency>().HasIndex("_Symbol")
                     .IsUnique();
         modelBuilder.Entity<global::BottomUp.Model.Currency>()
                     .Property(t => t.Code)
                     .IsRequired()
                     .HasField("_Code")
                     .UsePropertyAccessMode(PropertyAccessMode.Property)
                     .ValueGeneratedNever();
         modelBuilder.Entity<global::BottomUp.Model.Currency>()
                     .Property(t => t.Name)
                     .IsRequired()
                     .HasField("_Name")
                     .UsePropertyAccessMode(PropertyAccessMode.Property);
         modelBuilder.Entity<global::BottomUp.Model.Currency>()
                     .Property(t => t.Symbol)
                     .IsRequired()
                     .HasField("_Symbol")
                     .UsePropertyAccessMode(PropertyAccessMode.Property);

Which generates the following (initial) migration:

            migrationBuilder.CreateTable(
                name: "Currency",
                schema: "dbo",
                columns: table => new
                {
                    Code = table.Column<string>(nullable: false),
                    Name = table.Column<string>(nullable: false),
                    Symbol = table.Column<string>(nullable: false),
                    _Name = table.Column<string>(nullable: true),
                    _Symbol = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Currency", x => x.Code);
                });

I think the .HasIndex("_Name") are the problem. Changing them to .HasIndex(t => t.Name) seems to fix the issue.

@msawczyn msawczyn removed the released Issue is resolved in a current release label Oct 1, 2019
@msawczyn msawczyn added the released Issue is resolved in a current release label Oct 3, 2019
@msawczyn msawczyn modified the milestones: 1.3.0.6, 1.3.0.7 Oct 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug released Issue is resolved in a current release
Projects
None yet
Development

No branches or pull requests

2 participants