使用代码首先生成货币类型字段EF CTP5 [英] Generate money type fields using code first EF CTP5

查看:115
本文介绍了使用代码首先生成货币类型字段EF CTP5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这篇博文中: EF4 Code First Control Unicode和Decimal Precision,Scale with Attributes Dane Morgridge 使用属性来控制数据库上不同类型的创建。 p>

...我发现这个非常独特的BTW !!!



我如何在我的结果数据库使用EF CTP5的代码第一个API,如果可以使用约定或属性从您的模型中执行此操作?



抱歉,我的英文不是我的主要语言。



提前感谢

解决方案

例如,考虑这个发票类:

  public class Invoice 
{
public int InvoiceId {get;组; }
public decimal Amount {get;组;
}

您可以使用流畅的API:

  protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity< Invoice>()
.Property(i => i.Amount)
.HasColumnType(Money);
}

或者您可以使用数据注释:

  public class Invoice 
{
public int InvoiceId {get;组; }

[Column(TypeName =Money)]
public decimal数量{get;组; }
}


In this blog post: EF4 Code First Control Unicode and Decimal Precision, Scale with Attributes, Dane Morgridge used attributes to control the creation of different types on your database.

...And I found this pretty unique BTW!!!

How do I generate money type fields in my resulting database using code first API of EF CTP5, if is possible to do it from your model, using conventions or attributes?

Sorry about my English is not my main language.

Thanks in advance.

解决方案

For example, consider this Invoice class:

public class Invoice
{
    public int InvoiceId { get; set; }                
    public decimal Amount { get; set; }
}

You can do it with fluent API:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Invoice>()
                .Property(i => i.Amount)
                .HasColumnType("Money");
}

Or you can do it with Data Annotations:

public class Invoice
{
    public int InvoiceId { get; set; }                

    [Column(TypeName="Money")]
    public decimal Amount { get; set; }
}

这篇关于使用代码首先生成货币类型字段EF CTP5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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