WPF with EntityFramework error

本文关键字:error EntityFramework with WPF | 更新日期: 2023-09-27 18:13:51

我有一个基本的窗口,看起来像这样:

<Controls:MetroWindow x:Class="ShootingRangeClient.Shooters"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"
    Title="Shooters" 
    d:DesignHeight="600" d:DesignWidth="700">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="23" />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBox TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Stretch" Style="{StaticResource SearchTextBox}" TextChanged="TextBox_TextChanged_1"/>
        <DataGrid Name="ShootersDataGrid" Grid.Row="1" />        
    </Grid>
</Controls:MetroWindow>

和代码隐藏部分:

namespace ShootingRangeClient
{
    /// <summary>
    /// Interaction logic for Shooters.xaml
    /// </summary>
    public partial class Shooters
    {
        public SRDBEntities db;
        public Shooters()
        {
            InitializeComponent();
            db = new SRDBEntities();
            List<Shooters> sh = db.Shooters.Select(it => it).ToList();
            ShootersDataGrid.ItemsSource = sh;
        }
    }
}

一旦到这部分:

db.Shooters.Select(it => it)

我收到以下异常:

The component 'System.Data.Entity.DynamicProxies.Shooters_66339B43C72C5E730A746B2CE9B8CA7B6D2B66B2BC9DAE1C3BFCCD0C04B1CEC1' does not have a resource identified by the URI '/ShootingRangeClient;component/shooters.xaml'.

如何解决此错误?

WPF with EntityFramework error

养成以不同于标准对象的方式命名事物的习惯,并为所有生成的类提供唯一的名称。仅仅因为可以通过名称空间解决这个问题并不意味着它是最好的。正如你所看到的,机器和人一样很难读懂原作者的意图/思想。

对于测试数据也是如此,通过确保数据中没有克隆,这可能有助于调试或解释数据向前发展。