Entity Framework 5 (코드 첫 번째 메서드)를 사용하고 있으며 내 데이터베이스에 저장된 내 엔터티 중 하나를 갖고 싶습니다. DbContext
에 DbSet<>
속성)에는 DB에 저장되지 않은 관련 객체가 있습니다.Entity Framework의 DB가 아닌 관련 개체
// Stored in DB
public class RecordedMeasure
{
[Required]
public int RecordedMeasureID { get; set; }
[Required]
[StringLength(150)]
public string MeasureName { get; set; }
// Navigation Property...
// Go find the Measure by the MeasureName (which IS persisted to the DB)
public Measure Measure { get; set;}
// Additional properties removed for brevity....
}
// NOT Stored in DB
public class Measure{
public string MeasureName { get; set;}
// Additional properties removed for brevity....
}
// Allows registration and holds a static collection of all "Measures"
// that are known at runtime
public class MeasureRegistration{
// Allow access to all measures stored
public static List<Measure> Measures { get; set; }
// Register a measure
public static void Register(Measure measure) {
// Code removed for brevity...
}
}
엔티티 프레임 워크는 것 전형적인 DbSet 그것 같이 작업 할 수 있습니다 무언가로 내 MeasureRegistration.Measures
수집을 노출 할 수있는 방법이 있나요 : 아래
감사합니다.
업데이트/또한 명확한 설명
내가 그러나 데이터베이스에 매핑되는 속성을 방지하는 방법을 알고, 내가 EF 실제로 DbSet<>
같은 "저장소"또는 수집을 (가지고가는 방법을 알고하지 않다) DB 비 백업 모델과 비 DB 지원 모델 간의 관계를 수행하는 데 사용할 수있는 비 DB 백 모델입니다.
정확하게 "관계 성취"란 무엇을 의미합니까 – cheedep
'ModelContext.RecordedMeasures.FirstOrDefault(). Measure '의 줄을 따라 뭔가가 나옵니다. EF가 내'RecordedMeasure'의 'Measure' 속성을 수행하는 방법을 이해하게하십시오. 나는 이것이 "자동"이 아닐 것이라는 것을 깨달았고 나의 설계에 논리를 구축해야만한다. 나의 설계에 대한 나의 수집이 내 논리에 기초하여 질의되고 합쳐질 수있게 해준다. EF는 this.HasProperty (o => o.Measure) .WithMany (o => o.Measures) .HasForiegnKey (o => o.MeasureName);와 같은 매핑을 통해 이것을 수행하지만, DB를 치려고 시도했다.'Measure's는 거기에 저장되지 않는다. –
기본적으로, 나는 다른 Store backing'Measure's (Collection 또는 IQueryable을 통해 저장되는 나의 애플 리케이션 계층 또는 무엇이든간에)을 갖고 싶다. 필요한) EF를 통해 내 관계를 해결할 수있게합니다. 사용 가능한 기능이 아닐 수도 있습니다. –