Skip to content

Expression bodied properties fail to populate in db #2318

Closed as not planned
Closed as not planned

Description

@MatthewMWR

Ref: https://msdn.microsoft.com/en-us/magazine/dn879355.aspx

Using Beta4 EF in .Net app I see the following:

  1. Entity type has expression bodied (read only) property, e.g.:
    public string TitleInRFC1234Format => expression that calculates expected value from other property values
  2. Property is included in model and db schema by default (good)
  3. [UNEXPECTED] Upon SaveChanges() db column value is always null

Activity

  1. rowanmiller commented on Jun 12, 2015

    @rowanmiller
    Contributor

    @MatthewMWR given the property does not have a setter, the expected behavior is for EF to ignore it. I did a simple test using both Beta 4 and the latest nightly build and neither of these included the property in the model/database. Any chance you could share the code where you saw a column created for the property?

    Here is the code I was using to test it out...

       public class BloggingContext : DbContext
        {
            public DbSet<Blog> Blogs { get; set; }
    
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=ExpProps;Trusted_Connection=True;");
            }
        }
    
        public class Blog
        {
            public int BlogId { get; set; }
            public string Url { get; set; }
            public string UpperUrl => Url.ToUpper();
        }
  2. MatthewMWR commented on Jun 16, 2015

    @MatthewMWR
    Author

    Likely explanation is I did something in the builder/fluent layer to force the property creation in the database. Now that I understand expected behavior this thread becomes a dupe of #2319 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions