使用 WCF 数据服务将其发送到客户端后,部分类中的自定义属性不存在
所以我有一个从实体框架生成的事件类,我已经扩展了它在部分中生成的内容,如下所示:
public partial class Event
{
[DataMemberAttribute()]
public EventDate CurrentEventDate { get; set; }
}
当我在服务器上使用自定义属性时,它很好,例如:
[WebGet]
public IQueryable<Event> EventsOn(string date)
{
var to Return = // Get my events here
toReturn.ToList().ForEach(ev => ev.CurrentEventDate = ev.EventDates.Where(
evd => evd.StartDateTime.Date <= qDate.Date && evd.EndDateTime >= qDate.Date).Single());
return toReturn.AsQueryable();
}
但是当我尝试在 Javascript 中查看这个对象时,它告诉我:
错误:“CurrentEventDate”为 null 或不是对象
如何让自定义属性在发送出去后显示出来?
So I have an Event class which is generated from Enitity Framework, I have extended what it generated in a partial like so:
public partial class Event
{
[DataMemberAttribute()]
public EventDate CurrentEventDate { get; set; }
}
When I use the custom property ON THE SERVER it's fine, example:
[WebGet]
public IQueryable<Event> EventsOn(string date)
{
var to Return = // Get my events here
toReturn.ToList().ForEach(ev => ev.CurrentEventDate = ev.EventDates.Where(
evd => evd.StartDateTime.Date <= qDate.Date && evd.EndDateTime >= qDate.Date).Single());
return toReturn.AsQueryable();
}
But when I try and look at this object in Javascript, it tells me that:
Error: 'CurrentEventDate' is null or not an object
How can I have custom properties show up after they've been sent down the wire?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保两个
partial
类定义位于同一命名空间中。否则编译器会将它们变成两个单独的类并且不会警告您。Make sure that both of the
partial
class definitions are in the same namespace. Otherwise the compiler will turn them into two separate classes and not warn you.只是一个远景 - EventDate 似乎是一个自定义时间。如果是,那么您是否使用 Serialized 和 DataContract 属性(及其具有 DataMember 属性的属性)装饰它?
Just a long shot - EventDate seems to be a custom time. If yes then have you decorated it with Serializable and DataContract attributes (and its properties with DataMember attribute)?