仅为代码设置默认值 [英] setting default value for code only

查看:66
本文介绍了仅为代码设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用仅限代码在数据库级别为属性设置默认值

How do u set default value for a property at the database level using Code-Only

例如,如果我有一个名为CreateDate的属性,并且我希望其默认值为数据库是getdate(),我该怎么做。或另一个例子是为guid选择newid()..

For instance if i have a property called CreateDate and i want its default value in the database to be getdate(), how do i do it. or also another example be select newid() for guids..

Zeeshan

推荐答案

你好Zeeshan,

Hi Zeeshan,

Code First目前不提供提供列默认值的机制。

Code First doesn't currently provide a mechanism for providing column default values.

您需要手动修改生成的DDL才能添加他们。

You will need to manually modify the generated DDL to add them.

干杯,

Andrew。


这篇关于仅为代码设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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