我有這兩個實體屬性表達式無效。表達應代表屬性
public class Song : IPathHavingEntity
{
public int Id { get; set; }
[Required]
public string Path { get; set; }
[Required]
public virtual Album Album { get; set; }
[Required]
public int TrackNumber { get; set; }
}
public class Album : IPathHavingEntity
{
public int Id { get; set; }
[Required]
public string Path { get; set; }
public virtual IEnumerable<Song> Songs { get; set; }
[Required]
public int AlbumNumber { get; set; }
}
Path
在IPathHavingEntity
接口定義。
在我的Seed方法中,我只想爲Songs
表添加一首歌曲,但前提是它不存在。出於這個原因,我檢查專輯路徑和歌路組合並不因此增加它
context.Songs.AddOrUpdate(
s => new { FilePath = s.Path, AlbumPath = s.Album.Path },
new Song { TrackNumber = 1, Path = "01 Intro.mp3", Album = one });
問題之前就已經存在,則出現此錯誤
The properties expression 's => new <>f__AnonymousType0``2(FilePath = s.Path, AlbumPath = s.Album.Path)' is not valid. The expression should represent a property: C#: 't => t.MyProperty' VB.Net: 'Function(t) t.MyProperty'. When specifying multiple properties use an anonymous type: C#: 't => new { t.MyProperty1, t.MyProperty2 }' VB.Net: 'Function(t) New With { t.MyProperty1, t.MyProperty2 }'.
什麼問題?