Good morning Eager2008. Welcome to Microsoft Newsgroup Support service. My
name is Jialiang Ge [MSFT]. It's my pleasure to work with you on this issue.
I think your quote of "...execute the query again using the Execute method.
"is from the MSDN article
http://msdn.microsoft.com/en-us/library/bb738469.aspx
<quote>
To ensure that the data source is up to date, you may need to execute the
query again using the Execute method. This will bind the control to a new
ObjectResult. You should do this to ensure that object data is up-to-date in
the following cases:
1. Changes are being made to the same ObjectContext outside the bound
control.
2. Changes are being made to data in the data source.
3. Objects were returned using the NoTracking option.
</quote>
According to the description, your expectation of the DataBinding behavior
seems that, the ListView should be *refreshed automatically (without any
coding)* when changes happen in the persistent store. You also found that
manually calling the code:
listViewCtrl.DataContext = query.Execute(MergeOption.OverwriteChanges);
can force the ListView to be update-to-date.
In fact, this depends on *how we made the additions to the EntitySet*:
(A)
If the additions are made in the three ways of the above quote, it is
necessary to manually call query.Execute again as the MSDN article
illustrates.
listViewCtrl.DataContext = query.Execute(MergeOption.OverwriteChanges);
You understood the reason rightly: the control does not know about the new
ObjectResult and thus the control is not updated
By default, our data model does not have callback when changes happen in the
data source, thus ListView does not know that the underlying data is
changed. There are some technologies, like Sql Dependency, that allows us to
register a callback and refresh the view in the client application by
calling Execute in the callback function.
http://msdn.microsoft.com/en-us/library/t9x04ed2.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx
(If you want more materials about SqlDependency, please let me know)
(B)
If the additions are made in the bound control, e.g. Edit/Insert is enabled
in the ListView and the users modify/add data to it, the control will be
refreshed automatically according to the entity set. We do not need to write
any code to refresh the UI.
Does the above answer your question? Please don't hesitate to tell me if you
have any other questions or concerns. I will do my best to help you.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.