This is a migrated thread and some comments may be shown as answers.

Weird problem with ORM and WCF

11 Answers 102 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcelo
Top achievements
Rank 1
Marcelo asked on 18 Apr 2011, 10:37 PM
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);
}

11 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 19 Apr 2011, 08:12 AM
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
0
Marcelo
Top achievements
Rank 1
answered on 19 Apr 2011, 03:59 PM
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.
0
Alexander
Telerik team
answered on 21 Apr 2011, 03:53 PM
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
0
Marcelo
Top achievements
Rank 1
answered on 25 Apr 2011, 06:25 PM
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
0
IT-Als
Top achievements
Rank 1
answered on 26 Apr 2011, 02:21 PM
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
0
Marcelo
Top achievements
Rank 1
answered on 26 Apr 2011, 04:12 PM
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 ?
0
IT-Als
Top achievements
Rank 1
answered on 26 Apr 2011, 04:29 PM
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
0
Marcelo
Top achievements
Rank 1
answered on 26 Apr 2011, 04:45 PM
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 ?
0
IT-Als
Top achievements
Rank 1
answered on 27 Apr 2011, 07:53 AM
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...
0
Marcelo
Top achievements
Rank 1
answered on 27 Apr 2011, 03:51 PM
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();

 

 

 

0
Jan Blessenohl
Telerik team
answered on 29 Apr 2011, 10:06 AM
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
Tags
Getting Started
Asked by
Marcelo
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Marcelo
Top achievements
Rank 1
Alexander
Telerik team
IT-Als
Top achievements
Rank 1
Share this question
or