zoukankan      html  css  js  c++  java
  • 一个用户多个订单

    一个实体包含多实体。

    定义用户+订单。

     1   public class Order {
     2       public int RecordId { get; set; }
     3       public string RecordName { get; set; }
     4       public decimal Price { get; set; }
     5    }
     6    public class Person
     7    {
     8       public int RecordId { get; set; }
     9       public string Name { get; set; }
    10       
    11       //注意此 自动属性 的使用方法
    12       public IList<Order> OrderList { get; set; }
    13    }

    调用:

     1 class Program
     2    {
     3       static void Main(string[] args)
     4       {
     5          //订单1
     6          Order order1 = new Order();
     7          order1.RecordId = 1;
     8          order1.RecordName = "语文";
     9          order1.Price = 45.32M;
    10 
    11          //订单2
    12          Order order2 = new Order();
    13          order2.RecordId = 2;
    14          order2.RecordName = "数学";
    15          order2.Price = 55.67M;
    16 
    17          //订单集合
    18          List<Order> orderList = new List<Order>();
    19          orderList.Add(order1);
    20          orderList.Add(order2);
    21 
    22          //购买订单者:张三
    23          Person person = new Person();
    24          person.Name = "张三";
    25          person.RecordId = 1;
    26          person.OrderList = orderList;
    27 
    28          //打印张三订单的信息
    29          Console.WriteLine("购买者编号:" + person.RecordId + ";购买者:" + person.Name);
    30          Console.WriteLine("购买的教程:" + person.OrderList[0].RecordName + ";" + person.OrderList[1].RecordName);
    31 
    32          Console.ReadKey();
    33       }
    34    }

    打印:

  • 相关阅读:
    Android Studio踩的坑之导入别人的Android Studio项目
    获取已发布微信小游戏和小程序源码
    小程序第三方框架对比 ( wepy / mpvue / taro )
    项目中常用的MySQL 优化
    最全反爬虫技术
    MySQL Explain详解
    php接口安全设计
    PHP进程间通信
    PHP进程及进程间通信
    springBoot优雅停服务配置
  • 原文地址:https://www.cnblogs.com/leee/p/4507232.html
Copyright © 2011-2022 走看看