编辑:(简化的解决方案)我试图在可以有 N 张图片的广告实体中插入一个图片实体。图片与广告相关。
广告模型:
public class Ad
{
public int Id { get; set; }
public string Title { get; set; }
public virtual ICollection<Picture> Pictures { get; set; }
}
图片型号:
public class Picture
{
public int Id { get; set; }
public string URL { get; set; }
public int Ad_Id { get; set; }
public virtual Ad Ad { get; set; }
public int PictureType_Id { get; set; }
public virtual PictureType PictureType { get; set; }
}
图片类型型号:
public class PictureType
{
public int Id { get; set; }
public string Name { get; set; }
}
广告服务:
Picture picture = new Picture()
{
Ad_Id = adId,
Filename = newFileName,
PictureType_Id = pictureType.Id
};
_pictureService.CreatePicture(picture);
图片服务:
public void CreatePicture(Picture picture)
{
_pictureRepository.Add(picture);
_pictureRepository.Save();
}
错误:此代码生成的查询是:
执行阅读器“插入 [dbo].[Pictures]([Name], [Filename], [URL], [PictureType_Id], [Ad_Id], [PictureType_Id1], [Ad_Id1]) 值 (null, @0, null, @ 1,@2,空,空)”
我得到了错误:
抛出:“无效的列名‘PictureType_Id1’。无效的列名‘Ad_Id1’。” (System.Data.SqlClient.SqlException) 异常消息 =“无效的列名 'PictureType_Id1'。\r\n无效的列名 'Ad_Id1'。异常类型 = “System.Data.SqlClient.SqlException”,异常 WinRT 数据 = “”