2
EF가 "VideoClip"테이블에서 필드 값을 가져 오려고 시도하는 상황이 있습니다.EF의 열 이름이 잘못되었습니다
전체 생성 된 쿼리는 다음과 같습니다 그러나
SELECT
[Project1].[Id] AS [Id],
[Project1].[NewsItemId] AS [NewsItemId],
[Project1].[VideoClipId] AS [VideoClipId],
[Project1].[DisplayOrder] AS [DisplayOrder],
[Project1].[Video_Id] AS [Video_Id]
FROM (SELECT
[Extent1].[Id] AS [Id],
[Extent1].[NewsItemId] AS [NewsItemId],
[Extent1].[VideoClipId] AS [VideoClipId],
[Extent1].[DisplayOrder] AS [DisplayOrder],
[Extent1].[Video_Id] AS [Video_Id]
FROM [dbo].[NewsItemVideoClip] AS [Extent1]
WHERE [Extent1].[NewsItemId] = @p__linq__0
) AS [Project1]
ORDER BY [Project1].[DisplayOrder] DESC
, 내 NewsItemVideoClip
엔티티 클래스는 다음과 같습니다
public class NewsItemVideoClip : Entity
{
public virtual int NewsItemId { get; set; }
public virtual int VideoClipId { get; set; }
public virtual int DisplayOrder { get; set; }
public virtual NewsItem NewsItem { get; set; }
public virtual VideoClip VideoClip { get; set; }
}
매핑 :
public class NewsItemVideoClipEntityMapping
: EntityTypeConfiguration<NewsItemVideoClip>
{
public NewsItemVideoClipEntityMapping()
{
//configure key and properties
HasKey(c => c.Id);
this.HasRequired(x => x.NewsItem)
.WithMany(x => x.NewsItemVideoClips)
.HasForeignKey(x => x.NewsItemId);
this.HasRequired(x => x.VideoClip)
.WithMany(x => x.NewsItemVideos)
.HasForeignKey(x => x.VideoClipId);
//configure table map
ToTable("NewsItemVideoClip");
}
}
는 LINQ 쿼리 : Invalid column name 'Video_Id'
:
public IList<NewsItemVideoClip> GetVideoClips(int newsItemId)
{
var query = from nvc in _newsItemVideoClipRepository.GetAll()
where nvc.NewsItemId == newsItemId
orderby nvc.DisplayOrder descending
select nvc;
var newsItemVideoClips = query.ToList();
return newsItemVideoClips;
}
Howcome EF 나를 준다?
LINQ 쿼리를 게시 할 수 있습니까? – IronMan84
Video_Id는 비디오 테이블에서 예상하는 외래 키입니다. 비디오 모달 클래스와 유창한 매핑이 NewsItemVideoClip에 대한 많은/콜렉션 참조를 가지고 있는지 확인하십시오. – AaronLS
Omg! 그게 내가 한거야?))) – Roman