everyone! Here is my question: How can I retrieve quantity of Employees? In DomainService I have:
public IQueryable<employee> GetEmployeesCommon()
{
return this.ObjectContext. employees
.Where(t => t. is_record_delete == false)
;
}
public int GetNumberOfAllEmployees()
{
return GetEmployeesCommon()
.Where(t => t.idtypepc >= 2)
.Where(t => t.idtypepc <= 11)
.Count();
}
In DataService:
public void GetEmployeesAllEmployees(Action<InvokeOperation<int>> getEmployeesCallback)
{
Context.GetNumberOfAllEmployees(getEmployeesCallback, null);
}
And in ViewModel:
public void GetTechusAllPCs()
{
EmployeeDataService.GetEmployeesAllEmployees(getEmployeesCallback);
}
private void getEmployeesCallback(InvokeOperation<int> op)
{
EmpAll = op.Value;
}
private int _empAll;
public int EmpAll
{
get { return _empAll; }
set
{
_empAll = value;
RaisePropertyChanged("EmpAll");
}
}
I call GetTechusAllPCs() in LoadData() (after all entities retrieved) and then EmpAll has right value, but if change count of Employees (add or delete one) EmpAll will have same value as before. How can I get actual data?
Can somebody say what is wrong?
Maybe I am missing something.
I assume that you are putting the list of employees somewhere? or how could you add or delete an employee?
Why is EmpAll not a read only property that always returns the count of the collection. Then either take the easy way out and when you add or delete an employe, call RaisePropertyChanged("EmpAll"); once you know the submit went through.
Or the "better" way would be to add a handler to the collection's itemadded event and in that handler, just have the one line RaisePropertyChanged("EmpAll");
If its an observable collection the event would be collection changed.
If you want to know if any user added or deleted an employee you are going to have to either poll the server on a timer or use a duplex service.