SL4/WCF RIA Services/EF 4 응용 프로그램이 있습니다. 내 SL4 데이터 컨텍스트에 포함 된 엔티티를 가져 오는 데 문제가 있습니다.엔티티 프레임 워크/RIA 서비스가 작동하지 않음
[Query(IsDefault = true)]
public IQueryable<ToolingGroup> GetToolingGroups()
{
var groups = this.ObjectContext.ToolingGroups.Include("MetaData").OrderBy(g => g.Name);
return groups; //breakpoint set here
}
나는이 방법을 반환하기 전에 검사 할 수 있도록 VAR 그룹에 할당 : 응용 프로그램의 서버 측 서비스 부분에서
이 내 방법입니다. 내가 메서드가 반환하기 전에 중단 점을 설정하고 내 조사 식 창에 줄을 추가하면 메타 데이터가있다 : 나는이 방법을 반환하자와 실버의 UI를 완료 이벤트 메타 데이터를 확인groups.First().MetaData
가 null입니다.
void loadOperation_Completed(object sender, System.EventArgs e)
{
grid.ItemsSource = _toolingContext.ToolingGroups;
UpdateUI(); //breakpoint set here
}
내 시계 윈도우 메타 데이터에서이 작업을 수행
가 null :_toolingContext.ToolingGroups.First().MetaData
내가 반드시 두 경우 모두 좁은 방()에 대한 호출에 의해 반환 된 ToolingGroup가 같은 개체였다하게 확인하고 그것은이었다.
서비스 방법과 내 UI 방법간에 MetaData가 손실되는 이유는 무엇입니까 (예 : null)?
해결책 :
놀이에 두 개의 레이어가 여기에있다// The MetadataTypeAttribute identifies ToolingGroupMetadata as the class
// that carries additional metadata for the ToolingGroup class.
[MetadataTypeAttribute(typeof(ToolingGroup.ToolingGroupMetadata))]
public partial class ToolingGroup
{
// This class allows you to attach custom attributes to properties
// of the ToolingGroup class.
//
// For example, the following marks the Xyz property as a
// required property and specifies the format for valid values:
// [Required]
// [RegularExpression("[A-Z][A-Za-z0-9]*")]
// [StringLength(32)]
// public string Xyz { get; set; }
internal sealed class ToolingGroupMetadata
{
// Metadata classes are not meant to be instantiated.
private ToolingGroupMetadata()
{
}
public int Id { get; set; }
[Include] // Added so MetaData gets serialized
public MetaData MetaData { get; set; }
public Nullable<int> MetaDataId { get; set; }
public string Name { get; set; }
public ToolingCategory ToolingCategory { get; set; }
public int ToolingCategoryId { get; set; }
public EntityCollection<ToolingType> ToolingTypes { get; set; }
}
}
'메타 데이터'클래스의 이름을 '메타 데이터'로 지정하지 않아도됩니다! 'MetadataTypeAttribute'에서 설정 될 것이므로 원하는대로 자유롭게 이름을 지정할 수 있습니다 :) – AbdouMoumen
예 물론 테이블 뒤에 이름을 지정할 때 MetaData가 나쁜 선택 인 것으로 나타났습니다. 그러나 - [Include] 속성을 추가 할 위치가 표시되지 않습니다. –
이 스크린 샷을보고 내가 속성을 추가 할 적절한 위치에 있는지 확인할 수 있습니까? http://img855.imageshack.us/i/include.png/ 그렇지 않으면 내 솔루션에서 샘플과 비슷한 코드가 표시되지 않습니다. –