Print Page | Close Window

EntityQueryPagedCollectionView

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2400
Printed Date: 28-Mar-2025 at 5:19am


Topic: EntityQueryPagedCollectionView
Posted By: gregweb
Subject: EntityQueryPagedCollectionView
Date Posted: 25-Dec-2010 at 6:35pm
I put together a small app based on the sample using an EntityQueryPagedCollectionView.  It all works fine.  Now, I would like to add an item to the list. 
 
I use EntityQueryPagedCollectionView.Add() to add the item to the list, and it does add it to the list correctly.  And I can also save it correctly.  However, after the item is added, the list then locks up.  It can no longer be paged, nor sorted, nor can more than one item be added.  Any idea what is going on with this?
 
The code looks like this:
 
public void LoadContacts()
{
             var query = _mgr.ContactEntities;

this.Contacts = new EntityQueryPagedCollectionView(
query,
this.PageSize,
this.PageSize,
true,
false
);

this.Contacts.SortDescriptions.Add(new SortDescription("Last"ListSortDirection.Descending));
this.Contacts.Refresh();

}
internal void AddContact()
{
this.Contacts.AddNew();
}
internal void SaveContact()
{
EntitySaveOperation op = this._mgr.SaveChangesAsync();
op.Completed += new EventHandler<EntitySavedEventArgs>(op_Completed);
            
}

void op_Completed(object sender, EntitySavedEventArgs e)
{
EntitySaveOperation op = sender as EntitySaveOperation;
if (op.HasError)
{
MessageBox.Show(op.Error.Message);
}
            this.Contacts.Refresh();
}



Replies:
Posted By: sbelini
Date Posted: 29-Dec-2010 at 10:44am

Hi Greg,

 
When you call AddNew(), a new instance is created using EM.CreatEntity<T> and it goes into "Edit" mode (you probably want to add data to the new entity).
 
That's intentional - you can't page while an edit is underway.
 
Once you are done editting the entity, you must call CommitNew() (or CancelNew() if you want to dispose the entity) and then you can navigate/add items to the list.
The same happens if you are editing an existing item (i.e. this.Contacts.EditItem(this.Contacts.CurrentItem)) where you will need to call CommitEdit() or CancelEdit().
 
Silvio.


Posted By: gregweb
Date Posted: 30-Dec-2010 at 6:41am
Awesome, this works great.  I do so much appreciate the support - I might not have ever figured that one out on my own.
 
Greg



Print Page | Close Window