问题:如何在 WPF Core 应用程序中“添加新数据源”?
我执行了:
- 创建了一个 WPF Core 应用程序;
- 增加了课程CntDBSchool;
- 增加了课程Student;
- Menu Project//“添加新数据源”;
- 结果:没有课程Student;

类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 框架应用程序;
- 创建Model ADO.NET EDM;
- 在文件中DBModel.tt替换:
- 行 - 296 替换ICollection为ObservableCollection;
- 行 - 484 替换ICollection为ObservableCollection;
-- 第 51 行替换HashSet为ObservableCollection;
- - 行 - 431 替换System.Collections.Generic为System.Collections.ObjectModel;
- Menu Project//“添加新数据源”;
- 结果:课程Student在场;

