我需要根据 TPH 架构插入一个Picture
包含相关实体 ( ) 的实体 ():Ad
Picture
模型:
public class Picture
{
// Primary properties
public int Id { get; set; }
public string Name { get; set; }
}
public class AdPicture : Picture
{
public Ad Ad { get; set; }
}
Ad
模型:
public class Ad
{
// Primary properties
public int Id { get; set; }
public string Title { get; set; }
}
public class AdCar : Ad
{
public int? CubicCapacity { get; set; }
public int? Power { get; set; }
}
我想在 中插入一个新Picture
的AdCar
,我试过:
AdPicture picture = new AdPicture()
{
Ad = _adRepository.GetById(adId),
Filename = newFileName
};
_pictureService.CreateAdPicture(picture);
创建广告图片:
public void CreateAdPicture(AdPicture adPicture)
{
_adPictureRepository.Add(adPicture);
_adPictureRepository.Save();
}
但是实体框架说
*无效的列名“AdCar_Id”。*
当我检查 SQL 命令文本时,我可以看到
insert [dbo].[Pictures]([Name], [Filename], [URL], [Rank], [Discriminator], [PictureType_Id], [AdCar_Id], [Ad_Id])
values (null, @0, null, @1, @2, @3, @4, null)
它的投入AdCar_Id
和Ad_Id
,为什么?我怎样才能插入Picture
相关的AdCar
?