gpt4 book ai didi

c# - Ria 服务和导航属性问题

转载 作者:行者123 更新时间:2023-11-30 22:36:54 27 4
gpt4 key购买 nike

我在使用 Silverlight4、Ria 服务和 Entity Framework 时遇到问题。

我尝试从我的 sl 客户端通过 ria 服务获取一些数据,在我的 domainService 类中调用此方法:

public IQueryable<LastMinuteWachtLijstPromotie> GetLastMinuteWachtLijstPromoties(){
IQueryable<LastMinuteWachtLijstPromotie> list = (IQueryable<LastMinuteWachtLijstPromotie>)this.ObjectContext.LastMinuteWachtLijstPromoties.Include("Promotie");

return (from LastMinuteWachtLijstPromotie lwmp in list where lwmp.Actief select lwmp);
}

当我检查列表的内容时,在 Debug模式下,它充满了 LastMinuteWachtLijstPromotie 类型的对象。这些对象具有指向名为 Promotie 的对象的导航属性。我可以访问这些 Promotie 对象的属性。

然而,在 silveright 客户端上,加载完成时会调用一个方法:

public void OnLoadEntitiesCompleted(ServiceLoadResult<T> result) {

}

在这个方法中,我按预期获得了所有请求的 LastMinuteWachtLijstPromotie 对象,该属性然而,Promotie 为空。

我已经在自动生成的元数据类中的 Promotie 属性上设置了 [Include] 标签我使用 .Include("Promotie")

这些相同的方法用于我的域模型中的不同对象,这非常有效。此外,我似乎无法在 .edmx 文件中找到数据库映射和导航属性的差异。

有没有人遇到同样的问题或知道解决方案?

元数据类:

[MetadataTypeAttribute(typeof(LastMinuteWachtLijstPromotie.LastMinuteWachtLijstPromotieMetadata))]
public partial class LastMinuteWachtLijstPromotie
{

// This class allows you to attach custom attributes to properties
// of the LastMinuteWachtLijstPromotie 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 LastMinuteWachtLijstPromotieMetadata
{

// Metadata classes are not meant to be instantiated.
private LastMinuteWachtLijstPromotieMetadata()
{
}

public int AlertId { get; set; }

public string ArtikelNummer { get; set; }

public Nullable<int> ArtikelVariant { get; set; }

public int LastMinuteWachtLijstPromotieId { get; set; }

[Include]
public Promotie Promotie { get; set; }

public int PromotieArtikelId { get; set; }

public int PromotieId { get; set; }

public bool Actief { get; set; }

public DateTime Aanmaakdatum { get; set; }
}
}


[MetadataTypeAttribute(typeof(Promotie.PromotieMetadata))]
public partial class Promotie
{

// This class allows you to attach custom attributes to properties
// of the Promotie 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 PromotieMetadata
{

// Metadata classes are not meant to be instantiated.
private PromotieMetadata()
{
}

public string ActieType { get; set; }

public string AssortimentsManagerNaam { get; set; }

public string AssortimentsManagerTeamIds { get; set; }

[Display(Name = "Commerciele tekst")]
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Nokavision.ReclameFolder.UI.Web.Resources.ValidationResources))]
public string CommercieleTekst { get; set; }

[Display(Name = " ")]
public string CommercieleTekstDetails { get; set; }

[Include]
public Frame Frame { get; set; }

public Nullable<int> FrameId { get; set; }

public Nullable<DateTime> LastMinuteWijzigingsDatum { get; set; }

public string Opmerkingen { get; set; }

[Display(Name = "Op wachtlijst")]
public Nullable<bool> OpWachtLijst { get; set; }

//public Nullable<int> PromotieCopyId { get; set; }

public int PromotieId { get; set; }

[Include]
public EntityCollection<PromotieLeverancier> PromotieLeveranciers { get; set; }

[Include]
public EntityCollection<PromotieMutatie> PromotieMutaties{ get; set; }

//public Nullable<int> PromotieOrigineleId { get; set; }

[Include]
public EntityCollection<PromotieSymbool> PromotieSymbolen { get; set; }

public string Status { get; set; }

[Display(Name = "Promotie inhoud")]
public string PromotieInhoud { get; set; }

[Display(Name = "Promotie eenheid")]
public string PromotieEenheid { get; set; }

[Display(Name = "Promotie prijs")]
public decimal PromotiePrijs { get; set; }
}
}

最佳答案

添加Composition LastMinuteWachtLijstPromotieMetadata 类的属性 Promotie 属性。那么它应该可以工作。

public partial class LastMinuteWachtLijstPromotie {
internal sealed class LastMinuteWachtLijstPromotieMetadata{
[Include]
[Composition]
public Promotie Promotie { get; set; }
}
}

关于c# - Ria 服务和导航属性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6773445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com