我有一个MainBusinessLine类型,其ObservableCollection类型为Group,我从DomainService调用的方法返回一个可查询的MainBusinessLines列表。因此,在此方法中,我已确认所有相应的组都已添加到MainBusinessLines Groups集合中。但是当实体加载到客户端Silverlight应用程序中时,它几乎全部缺失。但是,踢球者是MainBusinessLine有另一个集合,它确实包含客户端加载操作后的所有适当的实体。我的关联属性是相同的,这意味着thisKey和otherKey的参数设置相似。
我也在创建POCO类而不是使用EntityFramework。以下是我的MainBusinessLine类的示例:
[Serializable,
DataContract]
public class MainBusinessLine : BaseDataContract
{
public MainBusinessLine()
{
}
private int _MainBusinessLineID;
[Key,
DataMember,
Required]
public int MainBusinessLineID
{
get
{
return _MainBusinessLineID;
}
set
{
if (_MainBusinessLineID == value)
return;
ReportPropertyChanging("MainBusinessLineID");
_MainBusinessLineID = value;
ReportPropertyChanged("MainBusinessLineID");
}
}
private ObservableCollection<LOBs> _DefaultLOBs;
[DataMember,
XmlIgnore,
SoapIgnore,
Include,
Association("DefaultLOBsCollection", "MainBusinessLineID", "MainBusinessLineID")]
public ObservableCollection<LOBs> DefaultLOBs
{
get
{
return _DefaultLOBs;
}
set
{
ReportPropertyChanging("DefaultLOBs");
_DefaultLOBs = value;
ReportPropertyChanged("DefaultLOBs");
}
}
private ObservableCollection<Groups> _Groups;
[DataMember,
Include,
Association("GroupsCollection", "MainBusinessLineID", "MainBusinessLineID")]
public ObservableCollection<Groups> Groups
{
get
{
return _Groups;
}
set
{
ReportPropertyChanging("Groups");
_Groups = value;
ReportPropertyChanged("Groups");
}
}
}
以下是LOB和Groups类:
[Serializable,
DataContract]
public class LOBs : BaseDataContract
{
private int _LOBID;
[Key,
DataMember,
Required]
public int LOBID
{
get
{
return _LOBID;
}
set
{
if (_LOBID == value)
return;
ReportPropertyChanging("LOBID");
_LOBID = value;
ReportPropertyChanged("LOBID");
}
}
private int _GroupID;
[DataMember]
public int GroupID
{
get
{
return _GroupID;
}
set
{
if (_GroupID == value)
return;
ReportPropertyChanging("GroupID");
_GroupID = value;
ReportPropertyChanged("GroupID");
}
}
private int _MainBusinessLineID;
[DataMember]
public int MainBusinessLineID
{
get
{
return _MainBusinessLineID;
}
set
{
if (_MainBusinessLineID == value)
return;
ReportPropertyChanging("MainBusinessLineID");
_MainBusinessLineID = value;
ReportPropertyChanged("MainBusinessLineID");
}
}
}
[Serializable,
DataContract]
public class Groups : BaseDataContract
{
private int _GroupID;
[Key,
DataMember,
Required]
public int GroupID
{
get
{
return _GroupID;
}
set
{
if (_GroupID == value)
return;
ReportPropertyChanging("GroupID");
_GroupID = value;
ReportPropertyChanged("GroupID");
}
}
private int _MainBusinessLineID;
[DataMember]
public int MainBusinessLineID
{
get
{
return _MainBusinessLineID;
}
set
{
if (_MainBusinessLineID == value)
return;
ReportPropertyChanging("MainBusinessLineID");
_MainBusinessLineID = value;
ReportPropertyChanged("MainBusinessLineID");
}
}
}
有人可以告诉我这里可能有什么问题吗?我觉得它与我设置关联属性的方式有关。感谢
答案 0 :(得分:1)
好的,所以我终于弄清楚我做错了什么。因此,我将简要但详细地解释如何设置“POCO DomainService”。我确信这不是唯一的方法,但这是我找到的最简单的方法,而且它有效。希望这能为其他人节省数周的头痛和挫折。
基本上,我的情况是我有一个MainBusinessLine类型,它有一个Groups集合和一个DefaultLOBs集合。但我没有包含的是我有一个GroupReference类型,它有一个MainBusinessLineID属性和一个GroupID属性。当我检索我的数据时,我继续循环遍历GroupsReference类型并将组添加到父MainBusinessLine的GroupsCollection。对于DefaultLOBsCollection也是如此。所以我在从DomainService“查询”之前填充了这个集合,并且存在问题。
在思考并阅读了我能找到的所有内容之后,Coding的神终于对我表示同情并给我一个答案。我将检索数据并创建每种类型的列表 WITHOUT 填充任何关联的集合属性。然后在其相应的查询方法中返回列表AsQuerable(),并且在客户端上生成的实体将使其EntityCollections满。
总而言之,如果您使用正确的密钥设置Include和Association属性而不尝试强制数据,那么您应该获得成功。我将包含我的新示例代码,希望这对其他人有用。
[Serializable,
DataContract]
public class MainBusinessLine : BaseDataContract
{
Int32 _MainBusinessLineID;
[Key,
DataMember,
Required]
public Int32 MainBusinessLineID
{
get
{
return _MainBusinessLineID;
}
set
{
if (_MainBusinessLineID == value)
return;
_MainBusinessLineID = value;
ReportPropertyChanged("MainBusinessLineID");
}
}
ObservableCollection<GroupsReference> _GroupsReferenceCollection;
[DataMember,
Include,
Association("GroupsReferenceCollection", "MainBusinessLineID", "MainBusinessLineID")]
public ObservableCollection<GroupsReference> GroupsReferenceCollection
{
get
{
return _GroupsReferenceCollection;
}
set
{
_GroupsReferenceCollection = value;
ReportPropertyChanged("GroupsReferenceCollection");
}
}
}
[Serializable,
DataContract]
public class GroupsReference : BaseDataContract
{
Int32 _GroupsReferenceID;
[Key,
DataMember,
Required]
public Int32 GroupsReferenceID
{
get
{
return _GroupsReferenceID;
}
set
{
if (_GroupsReferenceID == value)
return;
_GroupsReferenceID = value;
ReportPropertyChanged("GroupsReferenceID");
}
}
Int32 _MainBusinessLineID;
[DataMember,
Required]
public Int32 MainBusinessLineID
{
get
{
return _MainBusinessLineID;
}
set
{
if (_MainBusinessLineID == value)
return;
_MainBusinessLineID = value;
ReportPropertyChanged("MainBusinessLineID");
}
}
Int32 _GroupID;
[DataMember,
Required]
public Int32 GroupID
{
get
{
return _GroupID;
}
set
{
if (_GroupID == value)
return;
_GroupID = value;
ReportPropertyChanged("GroupID");
}
}
}
[Serializable,
DataContract]
public class Group : BaseDataContract
{
Int32 _GroupID;
[Key,
DataMember,
Required]
public Int32 GroupID
{
get
{
return _GroupID;
}
set
{
if (_GroupID == value)
return;
_GroupID = value;
ReportPropertyChanged("GroupID");
}
}
ObservableCollection<GroupsReference> _GroupsReferenceCollection;
[DataMember,
Include,
Association("GroupsReferenceCollection", "GroupID", "GroupID")]
public ObservableCollection<GroupsReference> GroupsReferenceCollection
{
get
{
return _GroupsReferenceCollection;
}
set
{
_GroupsReferenceCollection = value;
ReportPropertyChanged("GroupsReferenceCollection");
}
}
}
[EnableClientAccess(RequiresSecureEndpoint = false)]
public class DentalAdminPortalDomainService : DomainService
{
public DentalAdminPortalDomainService()
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
}
[Query]
public IQueryable<MainBusinessLine> GetMainBusinessLines()
{
return DataRepository.GetMainBusinessLines().AsQueryable<MainBusinessLine>();
}
[Query]
public IQueryable<Groups> GetGroups()
{
return DataRepository.GetGroups().AsQueryable<Groups>();
}
[Query]
public IQueryable<GroupLOBList> GetGroupsReference()
{
return DataRepository.GetGroupsReferences().AsQueryable<GroupsReference>();
}
}
再一次,我所做的就是从数据库中获取数据。使用反射创建每种类型的实例,设置属性值(不填充任何集合),并将它们添加到列表中。然后将列表返回给客户端。其余的都是由生成的代码完成的。
答案 1 :(得分:0)
您的XmlIgnore
媒体资源上的SoapIgnore
和public ObservableCollection<LOBs> DefaultLOBs
属性会成为您没有看到“MainBusinessLines”收藏品的原因吗?