【C#】ADO .Net Entities Framework使用查询语句时遇到的错误

发布时间:2020-07-04 23:21:10 作者:daniel8294
来源:网络 阅读:597

XAML代码:

<Window x:Class="WpfApplication72.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:WpfApplication72"

        mc:Ignorable="d"

        Title="MainWindow" Height="350" Width="525">

    <Grid>

        <DataGrid x:Name="listBox" ItemsSource="{Binding}" />


    </Grid>

</Window>

隐藏代码:

using System;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;


namespace WpfApplication72

{

    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    public partial class MainWindow : Window

    {

        private Formula1v2Entities data = new Formula1v2Entities();

        public MainWindow()

        {

            InitializeComponent();

            


            this.DataContext = collection;

        }


        public IEnumerable<object>collection

        {

            get

            {

                return (from r in data.Racers

                       select new

                       {

                         Id=r.Id,

                         FirstName=r.FirstName,

                         LastName=r.LastName,

                         Nationality=r.Nationality

                       }).ToList();


            }

        }

    }

}

在隐藏代码中如果没有ToList()方法的话,运行程序会报如下的错误:

Additional information: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList(). For ASP.NET WebForms you can bind to the result of calling ToList() on the query or use Model Binding,

for more information see http://go.microsoft.com/fwlink/?LinkId=389592.

参考链接:

https://www.devexpress.com/Support/Center/Question/Details/Q580427

推荐阅读:
  1. 【C#】使用ADO .Net Entities Framework 与WPF ListBox控件绑定
  2. C#提高知识 ADO.NET实体数据模型(3)-关于回滚

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

net ado entities

上一篇:C# 插入Excel页眉、页脚

下一篇:Exchange部署助理将逐步迁移到新地址

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》