ASP.NET MVC4, EntityFramework 코드 우선 및 면도기로 작성된 시스템이 있습니다. 모델 중 하나는 다음과 같은 문장이 있습니다EntityFramework : 불규칙한 이름으로 여러 개의 모델 구성
언급 한 바와 같이public class Flour : IEntityBase
{
[Key]
public Guid FlourId { get; set; }
public Guid ProcessId { get; set; }
[Display(Name = "Timestamp", ResourceType = typeof(Resources.Language))]
[Timestamp]
public Byte[] Timestamp { get; set; }
[Display(Name = "FlourAnalyzes", ResourceType = typeof(Resources.Language))]
public virtual ICollection<FlourAnalysis> FlourAnalyzes { get; set; }
[Display(Name = "Process", ResourceType = typeof(Resources.Language))]
public virtual Process Process { get; set; }
[Display(Name = "LastModified", ResourceType = typeof(Resources.Language))]
public DateTime LastModified { get; set; }
[Display(Name = "CreatedOn", ResourceType = typeof(Resources.Language))]
public DateTime CreatedOn { get; set; }
}
, Flour
는 FlourAnalysis
의 소장품이있다. 모델은 설명한다 : 마이그레이션을 생성 한 후
[Table(name: "FlourAnalyzes")]
public class FlourAnalysis : IEntityBase
{
[Key]
public Guid FlourAnalysisId { get; set; }
public Guid FlourId { get; set; }
public Guid? MeshId { get; set; }
[Display(Name = "Timestamp", ResourceType = typeof(Resources.Language))]
[Timestamp]
public Byte[] Timestamp { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd hh:mm}", ApplyFormatInEditMode = true)]
[Display(Name = "StartTimestamp", ResourceType = typeof(Resources.Language))]
public DateTime? StartTimestamp { get; set; }
[Display(Name = "HumidityPercentage", ResourceType = typeof(Resources.Language))]
[Range(0, 100)]
public Double HumidityPercentage { get; set; }
[Display(Name = "StarchPercentage", ResourceType = typeof(Resources.Language))]
[Range(0, 100)]
public Double StarchPercentage { get; set; }
[DataType(DataType.MultilineText)]
[Display(Name = "Comments", ResourceType = typeof(Resources.Language))]
public String Comments { get; set; }
[Display(Name = "Flour", ResourceType = typeof(Resources.Language))]
public virtual Flour Flour { get; set; }
[Display(Name = "Mesh", ResourceType = typeof(Resources.Language))]
public virtual Mesh Mesh { get; set; }
[Display(Name = "LastModified", ResourceType = typeof(Resources.Language))]
public DateTime LastModified { get; set; }
[Display(Name = "CreatedOn", ResourceType = typeof(Resources.Language))]
public DateTime CreatedOn { get; set; }
public FlourAnalysis() {
this.HumidityPercentage = 0;
this.StarchPercentage = 0;
}
, EF 이름 FlourAnalyzes
(나는 테이블 이름을 강제 할 필요가, 또는 다른 EF는 단일 테이블을 생성합니다)와 함께 테이블을 만들었습니다.
[Authorize]
public ViewResult Details(System.Guid id)
{
var flour = context.Flours
.Include(f => f.FlourAnalyzes)
.Single(x => x.FlourId == id);
return View(flour);
}
편집 : 그것으로 일부 데이터를 삽입 한 후, EF는 Flour
컨텍스트를 통해 개체를 호출 FlourAnalysis
데이터를 가져 오지 않는 몇 가지 제안 후
을, 나는 .Where()
에 .Single()
표현을 변경하고 생성 된 SQL 존재하지 않아야하는 열을 가리 킵니다. Flour_ProcessId
:
{SELECT
[Project1].[C1] AS [C1],
[Project1].[ProcessId] AS [ProcessId],
[Project1].[FlourId] AS [FlourId],
[Project1].[Timestamp] AS [Timestamp],
[Project1].[LastModified] AS [LastModified],
[Project1].[CreatedOn] AS [CreatedOn],
[Project1].[Mesh_MeshId] AS [Mesh_MeshId],
[Project1].[C2] AS [C2],
[Project1].[FlourAnalysisId] AS [FlourAnalysisId],
[Project1].[FlourId1] AS [FlourId1],
[Project1].[MeshId] AS [MeshId],
[Project1].[Timestamp1] AS [Timestamp1],
[Project1].[StartTimestamp] AS [StartTimestamp],
[Project1].[HumidityPercentage] AS [HumidityPercentage],
[Project1].[StarchPercentage] AS [StarchPercentage],
[Project1].[Comments] AS [Comments],
[Project1].[LastModified1] AS [LastModified1],
[Project1].[CreatedOn1] AS [CreatedOn1],
[Project1].[Flour_ProcessId] AS [Flour_ProcessId]
FROM (SELECT
[Extent1].[ProcessId] AS [ProcessId],
[Extent1].[FlourId] AS [FlourId],
[Extent1].[Timestamp] AS [Timestamp],
[Extent1].[LastModified] AS [LastModified],
[Extent1].[CreatedOn] AS [CreatedOn],
[Extent1].[Mesh_MeshId] AS [Mesh_MeshId],
1 AS [C1],
[Extent2].[FlourAnalysisId] AS [FlourAnalysisId],
[Extent2].[FlourId] AS [FlourId1],
[Extent2].[MeshId] AS [MeshId],
[Extent2].[Timestamp] AS [Timestamp1],
[Extent2].[StartTimestamp] AS [StartTimestamp],
[Extent2].[HumidityPercentage] AS [HumidityPercentage],
[Extent2].[StarchPercentage] AS [StarchPercentage],
[Extent2].[Comments] AS [Comments],
[Extent2].[LastModified] AS [LastModified1],
[Extent2].[CreatedOn] AS [CreatedOn1],
[Extent2].[Flour_ProcessId] AS [Flour_ProcessId],
CASE WHEN ([Extent2].[FlourAnalysisId] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C2]
FROM [dbo].[Flours] AS [Extent1]
LEFT OUTER JOIN [dbo].[FlourAnalyzes] AS [Extent2] ON [Extent1].[ProcessId] = [Extent2].[Flour_ProcessId]
WHERE [Extent1].[FlourId] = @p__linq__0
) AS [Project1]
ORDER BY [Project1].[ProcessId] ASC, [Project1].[C2] ASC}
내가 잘못하고있는 것은 무엇입니까?
문제를 재현 해 주실 수 있습니까? 무엇이 잘못되었는지 명확하지 않습니다. 수집 할 수있는 것부터,'modelBuilder.Conventions.Hemove();'규칙을 제거하는 데 관심이있을 것입니다. –
'Details' 메소드를 호출 할 때, 'Flours'를 가져 오는 컨텍스트 호출에서 관련 'FlourAnalyzes'가 검색되지 않습니다. 복수화 된 명명 규칙을 제거 할 필요는 없습니다. –
주어진 ID에 대해 데이터베이스에 관련 엔티티가 있는지 확인 하시겠습니까? – Pawel