WPF and ADO.NET EF - not working
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?
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.
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.
精彩评论