我正在使用ASP.NET MVC 4使用Entity FrameWork来执行数据库级操作 [英] Im working with ASP.NET MVC 4 using Entity FrameWork to perform database level operations

查看:68
本文介绍了我正在使用ASP.NET MVC 4使用Entity FrameWork来执行数据库级操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Entity FrameWork使用ASP.NET MVC 4来执行数据库级操作,现在我必须对此业务类进行验证,如果我将一个单独的类作为模型来绑定这些属性以查看我是否可以使用相同的由实体框架生成的类



Im working with ASP.NET MVC 4 using Entity FrameWork to perform database level operations, now i have to do validations for this business class, should i take a seperate class as model to bind these properties to view could i use the same class that was generated by entity framework

//------------------------------------------------------------------------------
// <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 NHMD.Models
{
    using System;
    using System.Collections.Generic;

    public partial class INVT_Item
    {
        public int ID { get; set; }
        public Nullable<int> ItemMasterID { get; set; }
        public Nullable<int> SchoolID { get; set; }
        public Nullable<int> WareHouseID { get; set; }
        public Nullable<int> YearID { get; set; }
}
}

推荐答案

数据首次验证 [ ^ ]



验证EF生成的模型类 [< a href =http://jnye.co/Posts/19/adding-validation-to-models-created-by-entity-framework-database-first-ctarget =_ blanktitle =New Window> ^ ]



在具有元数据属性的类的相同.cs文件中创建部分类将允许您应用验证。

Data first validation[^]

Validation to EF generated model classes[^]

Creating a partial class in the same .cs file for the class with Metadata attribute would allow you to apply validations.
[MetadataType(typeof(PayrollMarkupMetadata))
public partial class INVT_Item
{
  ...
}



希望这会有所帮助。

谢谢


Hope this helps.
Thanks


这篇关于我正在使用ASP.NET MVC 4使用Entity FrameWork来执行数据库级操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆