IdeaBlade DevForce 2010 Help Reference
AddEntity Method
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityManager Class : AddEntity Method



entity
Entity to be added.
Adds a newly created entity to the EntityManager cache.

Syntax

Visual Basic (Declaration) 
Public Sub AddEntity( _
   ByVal entity As Object _
) 
Visual Basic (Usage)Copy Code
Dim instance As EntityManager
Dim entity As Object
 
instance.AddEntity(entity)
C# 
public void AddEntity( 
   object entity
)
C++/CLI 
public:
void AddEntity( 
   Object^ entity
) 

Parameters

entity
Entity to be added.

Exceptions

ExceptionDescription
System.ArgumentExceptionEntity already belongs to another EntityManager

Example

C#Copy Code
DomainModelEntityManager mgr = new DomainModelEntityManager();

// Retrieve an order
Order order = mgr.Orders.FirstOrNullEntity(o=> o.OrderID == 1);
// Retrieve a product
Product product = mgr.Products.FirstOrNullEntity(p => p.ProductID == 1);

// Create an OrderDetail 
OrderDetail dtl = mgr.CreateEntity<OrderDetail>();
// assign key fields
dtl.OrderSummary = order;
dtl.Product = product;

// add the OrderDetail to the EntityManager cache
DebugFns.WriteLine("entity state before add = " + dtl.EntityState);
dtl.AddToManager();
DebugFns.WriteLine("entity state after add = " + dtl.EntityState);

Remarks

There is no difference between AddEntity and IdeaBlade.EntityModel.EntityAspect.AddToManager. Use either method to add a business object created by the CreateEntity method to the EntityManager cache. The object must have a "detached" EntityState. The added entity will have an entity state of "Added" after this method completes.

If the entity has an auto-incrementing EntityKey, the GenerateId method is called to create a temporary ID. See the Developer Guide for more information on custom ID generation.

The EntityChanging and EntityChanged events fire when this method executes with an EntityAction of EntityAction.Add.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.