如何在WPF Core应用程序中“添加新数据源”?

3

问题: 如何在WPF Core应用程序中“添加新数据源”?
我执行了以下操作:
 - 创建了一个WPF Core应用程序;
 - 添加了类CntDBSchool
 - 添加了类Student
 - 菜单项目 //"添加新数据源";
 - 结果:没有类Student
  enter image description here

enter image description here

CntDBSchool类。

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
 
namespace WpfApp.Models
{
    class CntDBSchool: DbContext
    {
        public virtual DbSet <Student> Student {get; set; }
    }
}

学生类 Student

using System;
using System.Collections.Generic;
using System.Text;
 
namespace WpfApp.Models
{
    class Student
    {
        public int StudentID {get; set; }
        public string StudentName {get; set; }
        public Nullable <int> StandardId {get; set; }
        public byte [] RowVersion {get; set; }
    }
}

表格 Student

 CREATE TABLE [dbo]. [Student] (
  [StudentID] int IDENTITY (1,1) NOT NULL,
  [StudentName] varchar (50) COLLATE Latin1_General_CI_AI NULL,
  [StandardId] int NULL,
  [RowVersion] timestamp NOT NULL,
  CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED ([StudentID])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY],
  CONSTRAINT [FK_Student_Standard] FOREIGN KEY ([StandardId]) REFERENCES [dbo]. [Standard] ([StandardId]) ON DELETE CASCADE ON UPDATE NO ACTION
)
ON [PRIMARY]

当我在WPF框架应用程序中执行相同操作时,在“添加新数据源”窗口中存在Student类。
我执行了以下步骤:
 - 创建了WPF Framework应用程序;
 - 创建了Model ADO.NET EDM
 - 在文件DBModel.tt中替换:
 - - 将第296行的ICollection替换为ObservableCollection
 - - 将第484行的ICollection替换为ObservableCollection
 - - 将第51行的HashSet替换为ObservableCollection
 - - 将第431行的System.Collections.Generic替换为System.Collections.ObjectModel
 - 菜单Project //" Add a new data source ";
 - 结果:出现了Student类;
enter image description here enter image description here

展示您在第一张截图中如何添加数据源以及所有步骤。 - Train
1
@Train 抱歉,我不明白你的问题。 我认为我已经按步骤描述了一切。 我没有更多要补充的了。 如果你方便的话,请更详细地描述你的需求。也许你有机会给出一个例子。 - eusataf
1个回答

2
今天我也遇到了这个问题。在WPF Framework应用程序中添加数据源是可以的,但在WPF Core应用程序中添加数据源却不行。我发现有人在19年7月份提交了一个问题:https://github.com/dotnet/wpf/issues/1196。他们认为这是因为核心版本不支持所有功能。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接