【发布时间】:2019-11-01 21:34:10
【问题描述】:
问题:如何在 WPF Core 应用程序中“添加新数据源”?
我表演了:
- 创建了一个 WPF 核心应用程序;
- 新增类CntDBSchool;
- 新增类Student;
- 菜单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;
- 菜单Project //“添加新数据源”;
- 结果:类 Student 存在;
【问题讨论】:
-
向我们展示您如何在第一个屏幕截图中添加数据源以及所有步骤。
-
@Train 对不起,我不明白你的问题。我想我分步描述了一切。我没有什么要补充的了。如果这对您来说并不困难,请更详细地描述您的要求。也许你有机会举个例子。
标签: c# wpf entity-framework entity-framework-core wpf-core