Weird problem with ORM and WCF

12 posts, 0 answers
  1. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 18 Apr 2011 Link to this post

    After create a Domain model in my Entities project, I select Data Services Wizard option in Telerik menu. I set Entities and Service (WCF project) projects and select WCF EndPoints Service in Data Service Type dialog. After I clicked in FInish button a several classes was generated.

    I create a new project, insert reference to my Entities project and a new Services refence and I started to test. Calling ReadAllArts method for one of my clases). The class i am using for test has five properties (Id, Name, Type (FK one to one) and List (FK one to many)). In data base there is only one register and there is no data for FK with one to many relationship. For my surprise only the field Id was filled, all ther others return null. Looking for a reason I put a breakpont into a method RealAllArts of SampleServiceName.svc.cs generated class. If I through quick watch feature I see de values everything is filled and when I press F5 to continue the processe the client can see all datas. Without use quick watch feature no. Other test I did was modify SampleServiceName.svc.cs and created a string and set the value with the property name. With this the client also see all data. It´s like some kind of lazy, not for FKs wich is normal, but for the own class.

    Another test I did was call ReadArt method. All data return ok.

    Bellow are the generated methods:

    /// <summary>
    /// Read Arts .
    /// </summary>
    /// <returns>List of Arts.</returns>
    public List<Entities.Art> ReadAllArts()
    {
        List<Entities.Art> list = dataManager.ReadEntities<Entities.Art>();
        // Without the line below only Id is filled
        string a = list[0].Name;
        return list;
    }
    /// <summary>
    /// Read Art.
    /// </summary>
    /// <param name="entityId">Art Id that will be read.</param>
    /// <returns>Target Art.</returns>
    public Entities.Art ReadArt(string entityId)
    {
        return dataManager.ReadEntity<Entities.Art>(entityId);
    }
  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 19 Apr 2011 Link to this post

    Hello Marcelo,
    Can you try list.ToList()? Sometime the serialization has problems with the IQueryable instead of a real List.

    Best wishes,
    Jan Blessenohl
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 19 Apr 2011 Link to this post

    Sorry for not having informed, but already has in my DAL tier.

    return Context.GetAll<T>().ToList();

    I don't think the problem is that because it was I believe the fields of the class will be filled and FKs and Lists not. In this case the own class properties are not filled, only the Id. If I put a line of code in any tier before the WCF just getting any propertie value all fields are filled. Why only PK is filled ?

    I'll do more tests.
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 21 Apr 2011 Link to this post

    Hello Marcelo,

    Do you get any exceptions thrown by OpenAccess or just no data is sent to the client?
    We discovered a bug in the official 2011 Q1 release, which could cause such behavior if the context has been disposed before the serialization is completed. I would suggest you to upgrade to the latest service pack (version 2011.1.411) and see if it helps. If the problem remains, please let us know, so we can continue investigating.

    Best wishes,
    Alexander
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 25 Apr 2011 Link to this post

    Sorry for delay.

    I open 417624 ticket with a attached solution wich demostrate the problem. Answering your questions, I already use 2011.1.411 and I not receive any kind of exception from OpenAccess
  7. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 26 Apr 2011 Link to this post

    Hi Marcelo,

    Where is the context maintained...I mean where do you create the Context and dispose it again. It seems like the context is detached from the persistent object before serialization and therefore no lazy loading is done during serialization.

    Regards

    Henrik
  8. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 26 Apr 2011 Link to this post

    Make sense, but I don´t see any reason to PK fileds are not null and all others fields are. Other question, if a force to read any of itens of collection this item will be all the fields filled and all others itens no.

    Your answer is based in my openned case ? If is I forced a dispose just to test, but without this happens the same behavior.

    When ORM worked with WCF whats is the best solution to retain context ? Use IDispatchMessageInspector in WCF tier and use AfterReceiveRequest and BeforeSendReply cabe be a option ?
  9. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 26 Apr 2011 Link to this post

    Hi Marcelo,

    When working with the WCF and ORM the dispatch message inspector could be a good place to create the context and dispose it again... Like I did in the article on my blog.

    However, this might not be the issue in your case... The reason for it working when you debug it, is because lazy loading is engaged when you inspect properties I guess..

    Just to make sure...have you included the other simple type properties (Name for instance) in the default fetch group?

    /Henrik
  10. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 26 Apr 2011 Link to this post

    Thanks for your reply.

    "However, this might not be the issue in your case... The reason for it working when you debug it, is because lazy loading is engaged when you inspect properties I guess.."

    I am not accessing via debug, I put string a = object.property. I think lazy shoud be only for FKs properties related and not for properties representing fields of the own class like NHibernate works. Am I right ?

    "Just to make sure...have you included the other simple type properties (Name for instance) in the default fetch group?"

    What you mean by "default fetch group". Is this some configuration ?
  11. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 27 Apr 2011 Link to this post

    Hi Marcelo,

    You are right. The default fetch strategy is to load on the fields in the default fetch group... and that is (by default) all primitive types of the class, unless you defined it to be something else.

    There should be an option in the designer for a field/property in a class, marking if it belongs to the default fetch group or not.

    The only thing I can think of is lazy loading, since if you access it before sending the reply to the client it works..
    However, doing a ToList() should "materialize" the persistent object so its default fetch group fields are loaded.

    Otherwise:
    Jan, can you elaborate further...
  12. Marcelo
    Marcelo avatar
    13 posts
    Member since:
    Feb 2011

    Posted 27 Apr 2011 Link to this post

    I agree with you, i think is a lazy loading problem, but I can´t find why.

    The only option I found related to this in designer was Load Behavior. The values for this option are Default, Lazy and Eager. Just for test I put Eager and neither this works.

    I already working with IDispatchMessageInspector.

    I still waiting for a awnser from support. I open a case I attached the entire solution.

    Edit : I already using ToList();

    var results = this.Context.GetAll<T>().OrderBy(orderField, orderDIrection);

     

     

     

    return results.ToList();

     

     

     

  13. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 29 Apr 2011 Link to this post

    Hi Marcelo,
    let me close this ticket and continue with #417624 otherwise it is too confusing and too many people are trying to answer your questions.

    Best wishes,
    Jan Blessenohl
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner