Solved

LINQ ReQuery

Posted on 2010-08-13
6
890 Views
Last Modified: 2013-11-11
LINQ queries seem to run once and reuse the selected data if the parameters don't change. - even it the data underneath has changed. In this code the query data is not refreshed eventhough I have changed the data in the database and I want to get the refreshed data.

    '** Load Default MWH Data
    Private Sub LoadDefaultMWH()
        '* DataContext is dc_MD
        '* Table is MD_MeterPoints
        Dim wrkMWH As Double
        '** Load Selected Date data
        Dim qDM = From DM In dc_MD.MD_MeterPoints _
          Select DM Where DM.P_ID = 210

        For Each recDM In qDM                                      '* there is only 1 record
            wrkMWH = recDM.P_DefaultAvailibility
        Next

How can I get LINQ to go back to the database when it thinks it already has what I want?

Thanks!

0
Comment
Question by:BEDMDunphy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33431849
Dim qDM = From DM In dc_MD.MD_MeterPoints
                  Where DM.P_ID == 210
                  Select DM

Try this code.
0
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33431926
I miss typed = twice.
0
 

Author Comment

by:BEDMDunphy
ID: 33432402
I see that you reversed the order of the WHERE and Select... I tried it but I get the same results. As an additional clue, I only get the refreshed data in this query if I actually close the application. I can see the updated data in another application function without closint the application.
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 33433225
Hi BEDMDunphy;

When you query the database and it returns records those records are saved in the DataContext. If your data in the database for those same records has changed by another process and you re-query the DB with the same DataContect as the original query the data for those records already in the DataContext will NOT be updated. If you change data in the records that are in the DataContext but have not executed a SubmitChanges the database will not be updated.

To get new changes that are in the database for records that are already in the DataContext execute a Refresh, something like the following :

DataContext.Refresh(RefreshMode.OverwriteCurrentValues, TheEntityTable)

For example

dc_MD.Refresh(RefreshMode.OverwriteCurrentValues, MD_MeterPoints)

Then the DataContext will have all the new values for the table MD_MeterPoints.

If you make changes to the DataContext you must do the following for the database to see them :

dc_MD.SubmitChanges()

Fernando
0
 

Author Comment

by:BEDMDunphy
ID: 33453338
Hi FernandoSOTO,

THANKS! For general information for other researchers on this issue - I did have to change the syntax slightly...

dc_MD.Refresh(RefreshMode.OverwriteCurrentValues, dc_MD.MD_MeterPoints)
 
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 33453862
Not a problem, glad to help.  ;=)
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS question 16 63
GUID's in SQL Server 4 31
Difference between Highcharts and Mapbox 10 44
VB.NET : Selection Out of Range Parameter Name : Value 22 35
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question