【发布时间】:2014-07-10 02:02:23
【问题描述】:
我是这项技术的新手。我正在尝试使用 MVVM(第一次)。在视图中,我有一个绑定到 ViewModel 中的属性 Calendardate 的日期选择器(这有效)。 WCF 测试客户端验证 GetEncounterTimesAsync()(无参数)是否正常工作。我已将 WCF 服务查询更改为使用 datetime 参数。该模型是从数据库中创建的一个实体框架。 (使用 Telerik 数据访问)。
我已经在互联网上搜索但没有成功。我没有使用任何网络服务(据我所知)。
我在下面所做的失败了。
如何将参数从 UI 传递到 WCF 并对实体执行查询?
如果不能做到这一点,如何通过 WCF 对 EntityFramerwork 进行参数化查询?
我很困惑,任何帮助将不胜感激。
(我的系统:Visual Studio 2010,Telerik Data Access)
视图模型:
public MaintenanceFormViewModel()
{
this.Calendardate = DateTime.Now;
}
private void RefreshEncountertimes()
{
// manage results when the WCF service returns
this.serviceClient.GetEncounterTimesCompleted += (s, e) =>
{
this.Encountertimes = e.Result;
};
// call the WCF service
this.serviceClient.GetEncounterTimesAsync(Calendardate);
}
private DateTime calendardate;
public DateTime Calendardate
{
get
{
return this.calendardate;
}
set
{
this.calendardate = value;
this.OnPropertyChanged("Calendardate");
this.RefreshEncountertimes();
}
}
我的 WCF 服务:
[ServiceContract]
public class ChaosService
{
[OperationContract]
public IEnumerable<Encountertime> GetEncounterTimes(DateTime encountertime)
{
using (var context = new ChaosModel())
{
var query = from et in context.Encountertimes
where et.Tencounter.Date == encountertime.Date
select et;
var result = context.CreateDetachedCopy(query.ToList());
return result;
}
}
}
【问题讨论】:
-
您是否尝试过更新 ServiceReference?
-
如何更新 ServiceReference?
-
非常基础,谷歌一下
标签: wpf entity-framework wcf mvvm telerik