转换和修改模型域作为一个DataColumn对象是 [英] Convert and modify a model field as an DataColumn object

查看:109
本文介绍了转换和修改模型域作为一个DataColumn对象是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET MVC 3,我想在创建数据库时,如果他们的DataColumn类的对象访问模型的领域,这样我就可以再修改的自动递增设置并存储了回去。

In ASP.NET MVC 3 I would like to access at database creation time the model fields as if they were objects of DataColumn class, so that I could then modify the auto-increment setting and store it back.

我的主要目标是使用code第一种方法来禁用一个模型的主键自动递增(标识设置)。

My primary target is to disable the auto-incrementing (identity setting) on the primary key of a model using code first approach.

推荐答案

这可能你所需要的。

public class MyModel
{
    [Key]
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.None)]
    public int MyID { get; set; }
}

这篇关于转换和修改模型域作为一个DataColumn对象是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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