Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:03:40+00:00 2026-05-15T10:03:40+00:00

I’m looking for a good guide into the right method of using Linq to

  • 0

I’m looking for a good guide into the right method of using Linq to Sql together with WPF.

Most guides only go into the bare basics like how to show data from a database but noone I found goes into how to save back to the database. Can you answer or point out to me a guide that can answer these questions.

I have a separate Data project because the same data will also be used in a web page so I have the repository method. That means I have a seperate class that uses the DataContext and there are methods like GetAllCompanies() and GetCompanyById ( int id ).

1) Where there are collections is it best to return as a IQueryable or should I return a list?

Inside the WPF project I have seen reccomendations to wrap the collection in a ObservabgleCollection.

2) Why should I use ObservableCollection and should I use it even with Linq / IQueryable

Some properties of the linq entities should be editable in the app so I set them to two-way mode. That would change the object in the observableCollection.

3) Is the object in the ObservableCollection still a instance of the original linq entity and so is the change reflected in the database ( when submitchanges is called )

I should have somekind of save method in the repository. But when should I call it? What happens if someone edits a field but decides not to save it, goes to another object and edits it and then press save. Doesn’t the original change also save? When does it not remember the changes to a linq entity object anymore. Should I instance the Datacontext class in each method so it loses scope when done.

4) When and how to call the SubmitChanges method

5) Should I have the DataContext as a member variable of the repository class or a method variable

To add a new row I should create a new object in a event ( “new” button push ) and then add it to the database using a repo method.

6) When I add the object to the database there will be no new object in the ObservableCollection. Do I refresh somehow.

7) I wan’t to reuse the edit window when creating new but not sure how to dynamically changing from referencing selected item from a listview to this new object. Any examples you can point out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:03:41+00:00Added an answer on May 15, 2026 at 10:03 am

    A lot of questions! I will answer a few.

    1) Use IQueryable whenever you wish to perform a LINQ query on it. Use of ‘var’ keyword instead of specifying a type is also preferred.

    2) ObservableCollection provides notification mechanism whenever the number of items in the collection changes. That way a list control can refresh itself whenever a collection changes.

    NOTE: you still need to implement INotifyPropertyChanged interface to notify property changes for individual objects in the collection.

    3) I recommend not storing LINQ entities directly into the collection. Reason is if you want to propagate changes back to database, you must keep the DataContext open from which that entity was created. That keeps the connection open and is not advised.

    4) Whenever you want to make changes in the database, create a new DataContext, select objects you want to change, change their properties and call SubmitChanges() method. Close the DataContext afterward.

    5) As I said, create a new instance of DataContext whenever you want to select objects out of database or submit changes back to the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.