2011-08-27 95 views
0

在服務器上我呼籲MeasurementService如何從ViewModel調用我的DomainService方法(帶參數)?

public MeasurementPresentationModel GetSingleMeasurementPM(Guid Id) 
    { 
     var m = this.ObjectContext.Measurments.SingleOrDefault(t => t.ID == Id); 
     return new MeasurementPresentationModel() 
       { 
        ID = m.ID, 
        Objective = m.Objective.Code, 
        ObjectiveID = m.ObjectiveID, 
        MeasurementList = m.MeasurmentList.Code, 
        MeasurementListID = m.MeasurementListID, 
        Weight = m.Wieght, 
        HasEvaluation = m.HasEvaluation, 
        ValidityEndDate = m.ValidityEndDate, 
        ValidityStartDate = m.ValidityStartDate, 
        DataType = m.DataType 
       }; 
    } 

上的DomainService類下面的方法在我的ViewModel我實例化域名服務MeasurementContext _context並試圖寫一個load方法巫婆不工作:

public MeasurementEditViewModel(MeasurementPresentationModel model):this() 
    {   
     _context = new MeasurementContext(); 
     var qry = _context.GetSingleMeasurementPMQuery(model.ID); 
     var lo = _context.Load(qry); 
     lo.Completed += (sender, e) => 
     { 
      SelectedMeasurement = lo.Entities; 
     } 
    } 

我做錯了什麼,我如何從ViewModels進行服務調用?

回答

0

加載方法是一種查詢方法,它應該返回IQueryable或IEnumerable。嘗試更改您的服務方式的合同,如:

public IEnumerable<MeasurementPresentationModel> GetSingleMeasurementPM(Guid Id)