Print Page | Close Window

Add entity to NavigationEntityProperty without retrieving values

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4095
Printed Date: 01-May-2025 at 8:43pm


Topic: Add entity to NavigationEntityProperty without retrieving values
Posted By: murray.bryant
Subject: Add entity to NavigationEntityProperty without retrieving values
Date Posted: 03-Apr-2013 at 11:46pm
I have the following code

  NavigationEntityProperty noteProp =
                        entity.EntityAspect.EntityMetadata.NavigationProperties.FirstOrDefault(
                            p => string.Equals(p.Name, "Notes"));
  var list = noteProp.GetValue(entity) as IList;

 list.Add(dSourceNote);

When I cast as IList the list is populated from the database.

I have no need to access the other values and for performance reasons in this case I would like to just add to the navigationentityproperty without selecting the other values from the database.

Is there any way I can do this?

thanks

Murray



Replies:
Posted By: sbelini
Date Posted: 04-Apr-2013 at 10:33am
Murray,

If you don't want the navigation property to retrieve entities from the database, you could force entity to act as if all its Notes have already been loaded:


EntityType.PropertyMetadata.Notes.GetEntityReference(entity).IsLoaded = true;


You can find additional information about navigation properties and data retrieval at http://drc.ideablade.com/devforce-2012/bin/view/Documentation/navigation-properties-data-retrieval - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/navigation-properties-data-retrieval .


Posted By: murray.bryant
Date Posted: 04-Apr-2013 at 2:55pm
thanks that works great



Print Page | Close Window