.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Entity Framework (EF) and ObservableCollection refresh

Posted By:      Posted Date: September 25, 2010    Points: 0   Category :WPF

I'm currently so frustrated and can't seem to find a solution on google or msdn.

I'm using EF classes.  In my code, I have a ObservableCollection (CustomerCollection) which is assigned to a CollectionViewSource.  The data load/save fine.  The problem is when I delete one of the customers in the datacontext, the listview does not remove it.  Can someone tell me how to fix this?  Do I have to use the collectionview to delete/add all the times?

    private DataContext db = new DataContext();
    private CustomerCollection CustomerData;
    private ListCollectionView customerView;

    private void Window_Loaded(object sender, RoutedEventArgs e)
      var query = from c in this.db.Customers
            where c.CompanyName.Contains(argSearchValue)
            || c.CustomerNo.Contains(argSearchValue)
            orderby c.CompanyName
            select c;

      var customerSource = ((CollectionViewSource)(this.FindResource("CustomerSource")));

      this.CustomerData = new CustomerCollection(query, this.db);
      customerSource.Source = this.CustomerData;
      this.customerView = ((ListCollectionView)(customerSource.View));


View Complete Post

More Related Resource Links

Refresh CollectionViewSource (Entity Framework) bound control

I can't believe I can't find an answer to this... I've created Entity Framework models generated from DB (SQL Server CE) I dragged an Entity from Data Sources to my MainWindow, automagically creating this XAML: <Window.Resources>     <CollectionViewSource x:Key="contentItemsViewSource" d:DesignSource="{d:DesignInstance my:ContentItem, CreateList=True}" /> </Window.Resources> <Grid DataContext="{StaticResource contentItemsViewSource}">     <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="Auto" HorizontalAlignment="Stretch" ItemsSource="{Binding}" Margin="0,22" Name="contentItemsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Stretch" Width="Auto" DataContext="{Binding}" IsReadOnly="True" CanUserResizeRows="False">         <DataGrid.Columns>             <DataGridTextColumn x:Name="idColumn" Binding="{Binding Path=Id}" Header="Id" Width="SizeToHeader" Visibility="Hidden" />             <DataGridTex

"The underlying provider failed on Open" - Entity Framework 4 starts after refresh


I have  deployed web-application on the hosting (asp.net 4.0, MS SQL 2008, IIS 7.0)

On the next day I have got this error message (I was the first, possible):

Inner Exception Type: System.Data.EntityException
Inner Exception: The underlying provider failed on Open.
Inner Source: System.Data.Entity
Inner Stack Trace:
at System.Data.EntityClient.EntityConnection.OpenStor

­eConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection
at System.Data.Objects.ObjectQuery`1.GetResults(Nulla
­ble`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collectio
at System.Collections.Generic.List`1..ctor(IEnumerabl
­e`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
­`1 source)
at Controls_basket.loadBasket ................................................

Then I pressed "F5" in my browser and my App started successfully.

refresh entity framework


I hope I'll explian properly.

I've some code that do DB updates. There are 2 parts to it.

1. the EF call the Stored Procedure to update DB. (this is big existing logic. so I can't rewrite in linq)

2. the EF + linq also does some DB operation in the same method.  At some point, it uses the DB changes done by SP.


The problem is that, EF can't recognise the changes done by SP.

When EF fetches the data, it still has the old values.

How do I refresh the EF?

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Creating a Generic Entity Framework 4.0 Repository

With .NET 4.0 right around the corner, I thought it would be cool to download Visual Studio 2010 beta 2 and start playing around with the next release of Entity Framework.

The initial release of Entity Framework came with a great deal of criticism. To make matters worse, there was a large uproar when it was rumored that Microsoft would be abandoning LINQ to SQL, in favor of Entity Framework. This was because, at the time, many developers felt Entity Framework was an inferior technology to LINQ to SQL. To set things right, Microsoft proactively moved forward with improving Entity Framework, in time for the 4.0 release of the .NET Framework. This is good news because my initial impressions, so far, have been nothing but positive.

ASP.NET 4.0 Dynamic Data and Many to Many Entity Framework Entities

I did not play much with Dynamic Data controls in VS2008 and just made a cool discovery in VS2010 Beta 2. This may not even be new, but as I'm sitting 30,000+ feet over the Atlantic ocean, I don't have access to VS2008 at the moment to check.

Entity Framework 4 Tips for WinForms Development

I've been recently working on a smart client (WinForms) application backed by Entitiy Framework 4 (EF4) on Visual Studio 2010. In this blog post I will try to give you some tips regarding some limitations and points to be careful about EF4.

Data accessors or Entity framework


The entlib 5 sugest me to use with data accessors for mapping data from database to my data objects (ORM).

But in .NET 3.5 and especially in .NET 4, I can use in entity framework as ORM methodology for data objects.

What data accessors uses advantages over the entity framework?

What differences that should be affect on my using decisions?

Data Points: Deny Table Access to the Entity Framework Without Causing a Mutiny


Julie Lerman shows database administrators how to limit access to databases from the Entity Framework by allowing it to work only with views and stored procedures instead of tables-without impacting application code or alienating developers.

Julie Lerman

MSDN Magazine August 2010

VS 2010: Entity Framework 4.0 and WCF Data Services 4.0 in Visual Studio 2010


Elisa Flasko takes you through a sample weblog application to demonstrate how new improvements in Entity Framework and WCF Data Services work together to simplify the way data is modeled, consumed and produced in Visual Studio 2010.

Elisa Flasko

MSDN Magazine April 2010

N-Tier Apps and the Entity Framework: Building N-Tier Apps with EF4


This article is the third in a series about n-tier programming with the Entity Framework, specifically about building custom Web services with the Entity Framework and WCF. This article looks at features coming in the second release of the Entity Framework (EF4) and how you use them to implement the Self-Tracking Entities and Data Transfer Objects (DTOs) n-tier patterns.

Daniel Simmons

MSDN Magazine November 2009

Entity Framework: N-Tier Application Patterns


This article examines n-tier patterns for success and some of the key APIs and issues specific to the Entity Framework. It also provides a sneak peak at features coming in the Microsoft .NET Framework 4 that should make n-tier development significantly easier.

Daniel Simmons

MSDN Magazine August 2009

Entity Framework: Anti-Patterns To Avoid In N-Tier Applications


Danny Simmons explores some anti-patterns you should look out for when building n-tier applications with the Entity Framework.

Daniel Simmons

MSDN Magazine June 2009

SOA Data Access: Flexible Data Access With LINQ To SQL And The Entity Framework


Building a data access layer using LINQ to SQL and the ADO.NET Entity Framework allows you to decouple your application from the persistence technology you're using.

Anthony Sneed

MSDN Magazine December 2008

ADO.NET: Achieve Flexible Data Modeling with the Entity Framework


Here the author answers questions regarding the Entity Framework and provides an understanding of how and why it was developed.

Elisa Flasko

MSDN Magazine July 2008

Data Points: The Entity Framework in Layered Architectures


Here we build a solution that fits the Entity Framework into an n-tier architecture that uses WCF and WPF and the MVP pattern.

John Papa

MSDN Magazine July 2008

Data Points: Entity Framework Q&A


The Entity Framework is a hot topic, but how do you know when to use EntityClient, Object Services, Entity SQL, or LINQ? Find out here.

John Papa

MSDN Magazine May 2008

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend