private void OnSearchExecute(IQueryable<SurveySearchCriteria> query)
{
SurveySearchCriteria ssc=query.Where(a => a.CriteriaString == "LastName").SingleOrDefault();
string format = ssc.WhereClause;
string args= string.Format(".{0}("{1}")", SelectedSearchType, EnteredSearchCriteria);
string returnval = string.Format(format, args);
ReadmissionTrackingApplication.Server.Services.SurveysDomainContext _context =
new ReadmissionTrackingApplication.Server.Services.SurveysDomainContext();
EntityQuery<ReadmitPatientList> eq = _context.GetReadmitPatientListByCriteriaQuery(returnval);
var lo= _context.Load<ReadmitPatientList>(eq);
使用这段代码,它不会填充我的low .entities。我有一种感觉,因为我没有使用回调,但查询在linqpad中工作得很好。
returnval= "PatientLastName.Contains("test")",当我把它插入linqpad时,它工作了。
ReadmitPatientList.AsQueryable()。("PatientLastName.Contains("测试")")
这是domainservice查询…
public IQueryable<Data.ReadmitPatientList> GetReadmitPatientListByCriteria(string formattedCriteriaString)
{
var query = this.ObjectContext.ReadmitPatientList.AsQueryable()
.Where(a => a.OriginalAdmitDate >= new DateTime(2010, 01, 01))
.Where(formattedCriteriaString);
return query;
}
我的问题是为什么这是在linqpad工作,而不是在我的代码。我使用silverlight,所以它可能是因为没有回调。这是我第一次尝试基于web的编程,所以我还在适应所有的复杂性…
这是一个回调问题。我重构了我的代码,以便它实现回调功能,并清理了Domainservice调用,现在它可以工作了。
客户服务:
public void getReadmitPatientList(System.Action<ICollection<ReadmitPatientList>> callback, string searchCriteria)
{
var q = _context.GetReadmitPatientListByCriteriaQuery(searchCriteria);
_context.Load<ReadmitPatientList>(q, OnReamitPatientListLoaded, callback);
}
public void getReadmitPatientList(System.Action<ICollection<ReadmitPatientList>> callback, int days)
{
DateTime CurrentDate = DateTime.Today;
DateTime entryDate = CurrentDate.AddDays(-days);
var q = _context.GetReadmitPatientListQuery().Where(a => a.OriginalAdmitDate >= entryDate);
_context.Load<ReadmitPatientList>(q, OnReamitPatientListLoaded, callback);
}
public void OnReamitPatientListLoaded(LoadOperation<ReadmitPatientList> lo)
{
if (!lo.HasError)
{
ICollection<ReadmitPatientList> q = new ObservableCollection<ReadmitPatientList>(lo.Entities);
var action = (Action<ICollection<ReadmitPatientList>>)lo.UserState;
action.Invoke(q);
}
else
{
MessageBox.Show(string.Format("{1}{0}{2}", Environment.NewLine, lo.Error.Message, lo.Error.InnerException));
lo.MarkErrorAsHandled();
}
}
域服务:
public IQueryable<Data.ReadmitPatientList> GetReadmitPatientListByCriteria(string formattedCriteriaString)
{
var query = this.ObjectContext.ReadmitPatientList.AsQueryable()
.Where(a => a.OriginalAdmitDate >= new DateTime(2010, 01, 01))
.Where(formattedCriteriaString);
return query;
}