Scaler value from int method on domainservice

1 posts, 0 answers
  1. Waleed Seada
    Waleed Seada avatar
    241 posts
    Member since:
    May 2006

    Posted 15 Feb 2011 Link to this post

    Dear all,
    I have a question where I define a custom method on the domainservice with the invoke attribute.
    I can call the method successfully from the client, but the problem is that the first call doesn't return the value, but in the second call it does .. funny isn't it ... what could be the reason.

    This method is responsible of returning the maxID for an entity (id is generated by the application).
    Method on the Domainservice:
    public int MaxCoinID()
        int coinid = GetIGL_coin().OrderBy(p => p.coin_id).ToList().Last().coin_id;
        return ++coinid;

    The call to this from client through Dataservice class as follows:
    public void GetNewCoinID()
        Context.MaxCoinID(MaxID_Loaded, null);
    public void MaxID_Loaded(InvokeOperation<int>invokeOperation)
        LastID = invokeOperation.Value;

    LastID is a property on the Dataservice class, which is being used in the save function at the same class as follows:

    public bool SaveCoin(IGL_coin coin)
        coin.coin_id = ++LastID;
        var ss = Context.SubmitChanges();
        if (ss.HasError)
            LastError = ss.Error.Message;
            return false;
        return true;

    it is an irrelevant question to telerik controls, but I am seeking help from professionals.
    Appreciate your help indeed.

    By the way:
    I tried to use the VQCV but I don't know how to get the Max id from the view here is the code:
            public bool SaveCoin(IGL_coin coin)
                var query = Context.GetIGL_coinQuery().OrderBy(p => p.coin_id);
                query.IncludeTotalCount = true;
                var view = new VirtualQueryableCollectionView() { LoadSize = 10, VirtualItemCount = 100 };
                view.ItemsLoading += (s, e) =>
                        Context.Load<IGL_coin>(query).Completed += 
                        (sender, args) =>
                            var lo = (LoadOperation) sender;
                            if (lo.TotalEntityCount != -1) view.VirtualItemCount = lo.TotalEntityCount;
                            view.Load(e.StartIndex, lo.Entities);
    //LastID = ((IGL_coin)view.GetItemAt(view.TotalItemCount - 1)).coin_id;

    The commented line gives converssion error !! 

Back to Top