locked
TryGetEntity returns always false RRS feed

  • Question

  • Hello,

    I'm using WCF Data Services with Generic types, My class looks like the following:

    public abstract class DataPagingViewModelBase<TContext, TEntity>

    Inside this class I want to refresh an entity (Which is the selected item by the end-user).

    To do that I created the following method:

    public void RefreshSelectedEntity()
            {
                var selectedEntity = this.SelectedDataItem;
                Uri identity;
                if (this.ServiceContext.TryGetUri(selectedEntity, out identity))
                {
                    this.ServiceContext.Detach(selectedEntity);
                    object loadedEntity;
                    if (this.ServiceContext.TryGetEntity(identity, out loadedEntity))
                    {
                        this.SelectedDataItem = (TEntity)loadedEntity;
                    }
                }
            }

    My question is: Why the method TryGetEntity is returning always false even if the Uri exist (I tested the url on the IE and it works without a problem). Knwoing that the URi (identity) is gotten by using the method TryGetUri.

    My second question is in the same context, The method TryGetUri Is working fine for me, except if the Entity was really edited by the user (using a wpf property grid control),

    So if the one or more properties are edited by the user , then, the method TryGetUri is always returning false also!!

    Can you help me please?

    Thursday, November 26, 2015 9:59 AM

Answers

  • >>My question is: Why the method TryGetEntity is returning always false even if the Uri exist (I tested the url on the IE and it works without a problem).

    It return false when the specified entity is not tracked by the DataServiceContext or is in the added state, no URI is available and false is returned.

    Please check if you are in this scenario.

    Also, please check this blog:

    http://blogs.msdn.com/b/dotnet/archive/2014/02/24/a-new-look-for-net-reference-source.aspx

    To have a try to debug the source code so that you are able to know why the method return false for you.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by cYounes Saturday, November 28, 2015 9:00 AM
    Friday, November 27, 2015 2:26 AM
    Moderator

All replies

  • >>My question is: Why the method TryGetEntity is returning always false even if the Uri exist (I tested the url on the IE and it works without a problem).

    It return false when the specified entity is not tracked by the DataServiceContext or is in the added state, no URI is available and false is returned.

    Please check if you are in this scenario.

    Also, please check this blog:

    http://blogs.msdn.com/b/dotnet/archive/2014/02/24/a-new-look-for-net-reference-source.aspx

    To have a try to debug the source code so that you are able to know why the method return false for you.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by cYounes Saturday, November 28, 2015 9:00 AM
    Friday, November 27, 2015 2:26 AM
    Moderator
  • You are right, it returns false because the entity is no more tracked by the service context after had been detached.

    this.ServiceContext.Detach(selectedEntity);
    Thanks for your answer.

    Saturday, November 28, 2015 9:00 AM