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 7955383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:42:03+00:00 2026-06-04T03:42:03+00:00

Is it possible to assign a collection from a database entity to an ObservableCollection

  • 0

Is it possible to assign a collection from a database entity to an ObservableCollection using entity framework?

This is what iv tried so far
I tried converting the list to an ObsrvableCollection using a constructor..but LINQ does not allow constructors which accept parameter.

Creating an extension for Ienumerable called ToObservable collection..but EF Does not recognize this.

Is there any other elegant solution to this.
Given below is the code i am using…and fails

using (var db = new clientEntities())
{
                var data = from p in db.CLIENTs
                           select new Contracts.Client()
                                      {
                                          ClientID = p.CLIENT_ID,
                                          FirstName = p.FIRST_NAME,                                          
                                          PayInfo = new ObservableCollection<PayInfo>(p.PAY_INFO.Select(n=> new PaymentInfo(){ 
                                              PayID=n.ID                                                    
                                              }))
                                      };
    }

The PayInfofield is an Observable collection. Is it possible to elegantly assign it without using temporary variables.

  • 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-06-04T03:42:04+00:00Added an answer on June 4, 2026 at 3:42 am

    It sounds like you’re confusing LINQ to Entities/SQL with plain-old LINQ. Remember that when you’re using the EF, any LINQ queries you write have to be translated into SQL. Thus, whatever object transformations you need to do on the data returned from the SQL database need to be directly supported by the EF. This includes ToList(), ToArray(), etc, but not your own custom extensions.

    I think the best you can do here is first query the database (you could use ToList() so the query executes), then use that resulting list in the constructor of the ObservableCollection (or call your ToObservableCollection() extension method.

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

Sidebar

Related Questions

Is it possible to assign Image to label text from Javascript I tried this
Using pointer arithmetic, it's possible to assign characters from one array to another. My
Possible Duplicate: Collection<T> versus List<T> what should you use on your interfaces? Consider this
is it possible to assign a value to a ServerVariable(Something) using the code? instead
Is it possible to assign the value a git command like git rev-list -n
Is it possible to assign list of objects to another list of objects that
Is it possible to assign a value to a class variable from inside a
Is it possible to assign php array in MySQL IN() function? for example, $numbers
Is it possible to assign a widget width to half the available screen width,
Is it possible to assign by reference? I know that ref has to be

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.