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