使用Code First创建数据模型

1、声明主键

using System;
using System.ComponentModel.DataAnnotations;

namespace MvcGuestbook.Models
{
public class Guestbook
{
[Key]
public int No{get;set;}
...
}
}

 

2、声明必填字段

using System;
using System.ComponentModel.DataAnnotations;

namespace MvcGuestbook.Models
{
public class Guestbook
{
[Key]
public int No{get;set;}
[Required]
public string Name{get;set;}
...
}
}

 

3、声明允许NULL字段

using System;
using System.ComponentModel.DataAnnotations;

namespace MvcGuestbook.Models
{
public class Guestbook
{
[Key]
public int No{get;set;}
[Required]
public string Name{get;set;}
public DateTime? CreatedOn{get;set;}
}
}

 

4、声明字段长度

using System;
using System.ComponentModel.DataAnnotations;

namespace MvcGuestbook.Models
{
public class Guestbook
{
[Key]
public int No{get;set;}
[Required]
[MaxLength(5)]
public string Name{get;set;}
public DateTime? CreatedOn{get;set;}
}
}

 

5、声明特定属性不是数据库中的字段

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MvcGuestbook.Models
{
public class Guestbook
{
[Key]
public int No{get;set;}
[Required]
[MaxLength(5)]
public string Name{get;set;}
public DateTime? CreatedOn{get;set;}
[NotMapped]
public string FamilyName{
get{return this.Name.Substring(0,1);}
set{this.Name=value.Substring(0,1)+this.Name.Substring(1);}
}
}
}

 

6、设计模型之间的关联性

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MvcGuestbook.Models
{
public class Guestbook
{
[Key]
public int No{get;set;}

public DateTime? CreatedOn{get;set;}

public Member Menber{get;set;}
}
public class Member
{
[Key]
public int No{get;set;}

[Required]
[MaxLength(5)]
public string Name{get;set;}

public ICollection<Guestbook> Guestbook{get;set;}
}
}

 

转载于:https://www.cnblogs.com/danznb/p/3565139.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
order_date sales_region_code item_code first_cate_code second_cate_code sales_chan_name item_price ord_qty 2016-03-15 101 20001 302 408 offline 700 102 2016-03-21 101 20001 302 408 offline 705 19 2016-03-23 101 20001 302 408 offline 702 36 2016-03-24 101 20001 302 408 offline 692 204 2016-03-25 101 20001 302 408 offline 693 36 2016-05-06 101 20001 302 408 offline 707 305 2016-05-09 101 20001 302 408 offline 709 206 2017-08-04 101 20002 303 406 offline 1958 4 2018-03-14 101 20002 303 406 offline 2166 2 2018-03-16 101 20002 303 406 offline 2466 3 2018-03-25 101 20002 303 406 offline 2453 3 2018-03-31 101 20002 303 406 offline 2462 9 以上数据是excel表格,你能看出来吗 上表表格保存在test.xlsx文件:order_date(订单日期,注:订单日期从2015 年 9 月 1日至 2018 年 12 月 20 日)、sales_region_code(销售区域编码)、item_code(产品编码)、first_cate_code (产品大类编码)、second_cate_code (产品细类编码)、sales_chan_name (销售渠道名称)、item_price (产品价格)和 ord_qty (订单需求量) 希望给出下列描述的python代码。 读入表格,将数据转为模型可用的格式。 训练集与测试集的数据要转换成模型可使用的数据格式,数据维度要与模型的输入相匹配。 使用tensorflow创建lstm模型,其训练数据为相同的产品编码,对应的订单日期,对应的订单需求量。然后进行模型训练 模型训练完成后,对不同的产品编码预测其在2019年1月至3月每月的订单需求量。 需要将信息保存在result.xlsx表格中,其中应包含以下数据,产品编码,和对应的2019年1月订单需求量,2019年2月的需求量,2019年3月的需求量。
04-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值