WPF 和 ADO.NET EF - 不工作
我正在编写一段代码,它从 sql ce 3.5 数据库获取记录,根据提供的 url 创建图像,然后用这些图像填充 observablecollection。它看起来像这样:
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);
}
}
当我尝试更改任何内容时,出现两个错误: 1) 无法从 IQueryable 转换为 IEnumerable 2) 连接字符串无效、对于提供者而言不正确或无法找到。具有 EF 模型和 app.config 的 DataAccessLayer 以及此代码放置在两个单独的项目中。
有什么建议如何正确编写吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)
交换
与
或仅
?
2) 连接 - 您需要在可执行文件中包含 app.config - 而不是在引用的项目中。根据您提供的信息,这就是我在没有更多信息的情况下所能弄清楚的。
1)
Exchange
with
or just
?
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.
WPF 应用程序框架 (WAF) 的 BookLibrary 示例应用程序展示了如何使用实体框架与 SQL CE 3.5 结合 WPF。
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.