Unless a fetch strategy
explicitly specifies otherwise, Telerik OpenAccess ORM does not load navigation properties until they are accessed. When using Web API, the serializer will access each of the properties of the object which is being serialized. This causes the navigation properties to be loaded. In order to prevent this behavior, before returning an entity you must detach it from its context using the CreateDetachedCopy
The method takes as arguments the entity or entities of which it should create detached copy or copies and a fetch strategy. The fetch strategy specifies which of the reference type properties should be detached and included in the copy. If no fetch strategy is passed to the method or the passed fetch strategy is just a fresh new instance, no reference type properties will be detached and included in the copy.
The code below will return all applications with Id = 37 without any of their navigation properties. Please note that when CreateDetachedCopy recieves an argument of type IQueryable, its return type is IEnumerable, therefore I have changed the return type of the method.
var entityModel =
"Data Source=.;Initial Catalog=Motion360Platform;Trusted_Connection=True"
entityModel.CreateDetachedCopy<Application>(entityModel.Applications.Where(w => w.Id == 37));
I hope this information will help you.
OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now
and play with the latest bits. See what's new >>