WPF 和 ADO.NET EF - 不工作

发布于 2024-09-05 12:19:50 字数 945 浏览 6 评论 0原文

我正在编写一段代码,它从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最笨的告白 2024-09-12 12:19:52

1)

交换

IEnumerable<library> libraryQuery =

IEnumerable<ElectricalLibrary> libraryQuery =

或仅

var libraryQuery =

2) 连接 - 您需要在可执行文件中包含 app.config - 而不是在引用的项目中。根据您提供的信息,这就是我在没有更多信息的情况下所能弄清楚的。

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.

飘然心甜 2024-09-12 12:19:52

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文