Print Page | Close Window

Add new objects to a ReadOnlyEntityList ...

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1081
Printed Date: 28-Jul-2025 at 9:14pm


Topic: Add new objects to a ReadOnlyEntityList ...
Posted By: msosa
Subject: Add new objects to a ReadOnlyEntityList ...
Date Posted: 04-Feb-2009 at 7:21am

Hi, I'm evaluating the product and so far it very good. The issue I'm dealing with is as folows: I have an User object that has an Roles property, witch is a relation with Rol object; so, an give user can have several roles. I want the administrator to be able to select those roles form a checkedlistbox. What I need to know is how to add those selected roles to the Roles property (a ReadOnlyEntityList) of the User object.

 
Thanks,
Maximiliano.



Replies:
Posted By: davidklitzke
Date Posted: 04-Feb-2009 at 8:31pm
You can't modify a ReadOnlyEntityList (that's why it is a "ReadOnlyEntityList"), but usually you  can create a new ReadOnlyEntityList.  For example, here is how I might modify the Cache strategy for Orders, a ReadOnlyEntityList<Order>

public override ReadOnlyEntityList<Order> Orders {

get {

return new ReadOnlyEntityList<Order>(this.PersistenceManager.GetChildren<Order>(this, EntityRelations.Employee_Order, QueryStrategy.DataSourceThenCache, true));

}

}



Posted By: kimj
Date Posted: 06-Feb-2009 at 11:08am
Maximiliano,
 
In DevForce Classic, you can't directly add or remove items from the list returned by a navigation property.  Fortunately, this ReadOnlyEntityList is actually a "live" list and will effectively monitor actions on the PersistenceManager for items to be added or removed.  In your case, you should see new items in the User.Roles list when you create a new "UserRole" entity (and add it to the PM).  I'm assuming that you have some sort of "UserRole" linking entity which contains foreign keys to the "User" and "Role" objects - so to add a specific role to a user you create a new "UserRole" object for that user.



Print Page | Close Window