티스토리 뷰

반응형

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);

 

 

반응형
댓글
댓글쓰기 폼
반응형
Total
731,768
Today
377
Yesterday
407
«   2022/12   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함