在 ASP.NET MVC 4 上工作,我为 Entity Framework 5 项目创建了单独的类库,我已将对该 EF 项目(类库)的引用添加到我的 MVC Web 项目中。
EF:使用Schema First
将我所有的表都拉到我的.EDMX
.
EFModel.edmx :=>
EFModel.tt
>>>Address.cs
>>>Requester.cs <<<=== (I'm working on this particular model object)
<<<More...>>>
示例 Requester.cs 自动生成的代码模板:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace issoa_ef
{
using System;
using System.Collections.Generic;
public partial class requester
{
public requester()
{
}
public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public Nullable<bool> Active { get; set; }
public Nullable<int> CreatedById { get; set; }
public string CreatedBy { get; set; }
public Nullable<System.DateTime> CreatedDateTime { get; set; }
public Nullable<int> ModifiedId { get; set; }
public string ModifiedBy { get; set; }
public Nullable<System.DateTime> ModifiedDateTime { get; set; }
}
}
返回 MVC 项目:
MVC==> Model==> Folder
我为Requester
较短的版本创建了一个模型类,这是我在 MVC 模型文件夹中创建的原因,以便我可以拥有我的数据注释并将数据属性装饰到我的道具。
请求者.cs
namespace issoa_mvc.Models
{
public class Requesters
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public Nullable<bool> Active { get; set; }
}
}
Scaffolding
为请求者创建
错误屏幕: