我无法理解如何在我正在构建的项目上的类之间创建关系。实体框架5代码第一关系
我有一个类Photo
具有与PhotoExif
所需一对一的关系,并Photo
具有FeaturedPhoto
可选的一对一的关系。
,我发现了错误:
Unable to determine composite primary key ordering for type
Website.Models.PhotoExif
. Use theColumnAttribute
or theHasKey
method to specify an order for composite primary keys.
帮助将非常感激。
Photo.cs
public class Photo
{
[Key]
public int PhotoID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public Orientation Orientation { get; set; }
public int Rating { get; set; }
public string URL { get; set; }
public string Filename { get; set; }
public DateTime DateAdded { get; set; }
public bool Hide { get; set; }
public string MetaDescription { get; set; }
public string MetaKeywords { get; set; }
public virtual PhotoExif PhotoExif { get; set; }
}
PhotoExif.cs
public class PhotoExif
{
[Key]
public int PhotoExifID { get; set; }
public int PhotoID { get; set; }
public string ShutterSpeed { get; set; }
public string Aperture { get; set; }
public string FocalLength { get; set; }
public int ISO { get; set; }
public string ExposureBias { get; set; }
public bool Flash { get; set; }
public string WhiteBalance { get; set; }
public string Lens { get; set; }
public DateTime DateTaken { get; set; }
public float Longitude { get; set; }
public float Latitude { get; set; }
public int Zoom { get; set; }
public string Location { get; set; }
public virtual Photo Photo { get; set; }
}
FeaturedPhoto.cs
public class FeaturedPhoto
{
[Key]
public int FeaturedPhotoID { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string InformationLocation { get; set; }
public string ImagePosition { get; set; }
public virtual Photo Photo { get; set; }
}
您似乎缺少Photo中FeaturedPhoto的导航属性,但除此之外,这里实际上有什么错误?你有错误吗?导航属性不起作用吗? – control
http://stackoverflow.com/a/11914424/114029 –