views:

23

answers:

2

Hi, I'm writing a piece of code that takes the records from a sql ce 3.5 database, creates images based on the url provided and then fill the observablecollection with those Images. It looks like this:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    Entities db = new Entities();
    ObservableCollection<Image> _imageCollection =
   new ObservableCollection<Image>();

    IEnumerable<library> libraryQuery =
    from c in db.ElectricalLibraries

    select c;

    foreach (ElectricalLibrary c in libraryQuery)
    {
        Image finalImage = new Image();
        finalImage.Width = 80;

        BitmapImage logo = new BitmapImage();
        logo.BeginInit();
        logo.UriSource = new Uri(c.url);
        logo.EndInit();

        finalImage.Source = logo;

        _imageCollection.Add(finalImage);

    }

}

I'm getting two errors, when I try to change anything: 1) Cannot convert from IQueryable to IEnumerable 2) The connection string is not valid, not correct for the provider or cannot be found. The DataAccessLayer with the EF model and app.config and this code are placed in two separate projects.

Any suggestions how to write it properly?

A: 

1)

Exchange

IEnumerable<library> libraryQuery =

with

IEnumerable<ElectricalLibrary> libraryQuery =

or just

var libraryQuery =

?

2) Connection - you need to have the app.config in the executable - not in the referenced project. As per the information you gave that's about as much as I can figure out without more information.

Goblin
using "var" will work (but correcting the generic typename should fail)
DK
Hmm? IQueryable<T> implements IEnumerable<T> Isn't the db.ElectricalLibraries a collection of ElectricalLibrary?
Goblin
Some of the names from the model were plurized I think. So the answer is yet, it is a collection. But the problem seems to be that I cannot convert between two types of collections for some reason. The other problem - should I copy the entire app.conf into the module? Or the project that holds shell module?
Enzomatric
A: 

The BookLibrary sample application of the WPF Application Framework (WAF) shows how to use the Entity Framework with SQL CE 3.5 in combination with WPF.

jbe