The properties expression is not valid. The expression should represent a property

In my case, The Only modification I did that on the Model Classes forget to put {get; set;} with the property declaration, Thus ...It's solved my problem.

Like this:

Before:

 public int Supplier_ID;
 public String Supplier_Code;

After:

 public int Supplier_ID { get; set; }
 public String Supplier_Code { get; set; }

Kindly Check your Model Classes should have the Get/Set property


I struggled with a similar issue for several hours today and was finally able to resolve it. I'm not sure if this will work for your situation but it's worth investigating.

The problem may be caused by the Album property of your Song entity being marked as virtual. I'm not an EF expert but I don't think it likes that virtual property when initializing your anonymous type. Add a non-virtual property for the album path (but keep the virtual navigation property), like this:

public class Song : IPathHavingEntity
{
    public int Id { get; set; }

    [Required]
    public string Path { get; set; }

    [Required]
    public virtual Album Album { get; set; }

    public string AlbumPath { get; set; }

    [Required]
    public int TrackNumber { get; set; }
}

And then perform the AddOrUpdate using that non-virtual property, like this:

context.Songs.AddOrUpdate(
    s => new { FilePath = s.Path, AlbumPath = s.AlbumPath }, 
    new Song { TrackNumber = 1, Path = "01 Intro.mp3", Album = one });

EF should then only allow you to add songs where the given song path and album path do not already exist. Whether your Song domain object can have a non-virtual AlbumPath property is another question but this should at least allow you to run your seed method in the way you described.


EF does not create a column for a property which does not have either getters or setters. For example, EF will not create columns for the following City and Age properties.

using System.ComponentModel.DataAnnotations;

public class Student
{
    private int _age = 0;

    public int StudentId { get; set; }
    public string StudentName { get; set; }
    public string City { get{ return StudentName;}  }
    public int Age { set{ _age = value;}  }
}

Referance : https://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-first.aspx