티스토리 뷰

반응형

1. EntityQuery를 이용해서 클라이언트에서 조건을 추가해서 조회하기


//Server side

[Query]
public IQueryable<VisitReservation> GetVisitReservations(int siteid)
{
        var results = from kkk in this.ObjectContext.VisitReservations
                                    .Include("Visitors")

                                    .Include("Visitors.Cards")
                                    .Include("VisitorUsers")
                                    .Include("VisitorPermissions")
                      where kkk.SiteId == siteid
                      orderby kkk.ReservedOn
                      select kkk;

 

        return results;
}

 

//Client side

using System.ServiceModel.DomainServices.Client;

 

DateTime start = new DateTime(this.StartDate.Year, this.StartDate.Month, this.StartDate.Day, 0, 0, 0);
DateTime end = new DateTime(this.EndDate.Year, this.EndDate.Month, this.EndDate.Day, 23, 59, 59);

var query = from kkk in DomainContext.GetVisitReservationsQuery(this.SiteId)
            where kkk.ReservedOn >= start 
                && kkk.ReservedOn <= end
                && (kkk.UserId == User.Id || kkk.ApproverId == User.Id)
            select kkk;

 

this.DomainContext.Load(query, LoadBehavior.RefreshCurrent,
    lo =>
    {
        if (lo.HasError == true)
        {
            lo.MarkErrorAsHandled();
            MessageBox.Show(string.Format(StringTable.FailedToLoadData, lo.Error.Message));
            return;
        }

        this.VisitReservations = new ObservableCollection<VisitReservation>(lo.Entities);
        this.SearchResult = string.Format("[{0} {1}]", StringTable.SearchResults, this.VisitReservations.Count);
    }, null);

 

 

반응형
댓글