使用实体框架代码第一个CTP5,如何创建一个主键列,它们是INT,而不是标识列 [英] Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

查看:107
本文介绍了使用实体框架代码第一个CTP5,如何创建一个主键列,它们是INT,而不是标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用实体框架代码第一个CTP5,如何创建一个主键列,它们是INT,而不是标识列

Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

最好不要使用属性。

推荐答案

如果您使用流畅的界面构建实体,而不是在属性上使用属性,则可以使用DatabaseGenerationOption类来自EntityFramework.dll,在System.ComponentModel.DataAnnotations命名空间中)。我没有测试过,但这是它的样子:

If you're building your entities using the fluent interface rather than using attributes over the properties, you may be able to use the DatabaseGenerationOption class (from EntityFramework.dll, in the System.ComponentModel.DataAnnotations namespace). I've not tested it, but this is what it would look like:

modelBuilder
    .Entity<Foo>()
    .Property(f => f.Id)
    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

这篇关于使用实体框架代码第一个CTP5,如何创建一个主键列,它们是INT,而不是标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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