在实体框架如何设置默认值实体、默认值、如何设置、框架

由网友(搜不出她的心)分享简介:我有一个表在我的数据库52列,我想编写一个函数,以该表中创建行。就我而言,我不希望使用的所有列在该表中,所以我创造了我的模型是这样的。I've a table with 52 columns in my database and I want to write a function to create a row...

我有一个表在我的数据库52列,我想编写一个函数,以该表中创建行。 就我而言,我不希望使用的所有列在该表中,所以我创造了我的模型是这样的。

I've a table with 52 columns in my database and I want to write a function to create a row in that table. In my case, I don't want to use all columns in that table, so I created my model like this.

[Table("CUST_MASTER")]
public class CustomerMaster
{
    [Key]
    [Column("CUSTOMER_ID")]
    public string Id { get; set; }

    [Column("CUSTOMER_NAME")]
    public string Name { get; set; }

    [Column("CUSTOMER_CITY")]
    public string City { get; set; }
 }

有没有办法通过实体框架,而无需编写所有在我的模型领域和做只发送这些数据并设置所有其他不可为空领域的一些默认数据(字符串,对于小数0.0等)手动?

Is there any way to send only this data via Entity framework and set all other not nullable fields to some default data(for strings "", for decimals 0.0, etc.) without writing all that fields in my model and doing it manually?

推荐答案

在没有纳入表列模型中的话,就不会被映射,它会被完全忽略所有生成的SQL。

When you do not incorporate a Table-column in your model then it won't be mapped and it will be totally ignored by all generated SQL.

所以,唯一的选择是指定在数据库中的默认值。

So the only option is to specify a default value in your Database.

阅读全文

相关推荐

最新文章