none
通过单独表实现层级关联在EF中如何用Fluent API描述? RRS feed

  • 问题

  • 雇员

        public class Employee
        {
            public int id { get; set; }
            public String guid { get; set; }
            public String name { get; set; }
            public DateTime dt_hired { get; set; }
    
            public virtual Employee Leader { get; set; }
            public virtual ICollection<Employee> Staff { get; set; }
        }

    层级关系表

    CREATE TABLE `e2e` (
    	`id` INT(11) NOT NULL AUTO_INCREMENT,
    	`e0` VARCHAR(50) NOT NULL COMMENT '上级guid',
    	`e1` VARCHAR(50) NOT NULL COMMENT '下级guid',
    	`dt_assigned` DATETIME NOT NULL,
    	PRIMARY KEY (`id`)
    )

    这个如何用Fluent API描述呢?



    • 已编辑 aze 2017年3月28日 7:02 完善问题
    2017年3月28日 6:47

全部回复

  • 你好,

    请问 e0 和 e1 是其他表的外键吗?

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年3月29日 5:34
    版主
  • 对的

    e2e表中的e0和e1都是对应Employee表的guid列


    2017年3月29日 8:52
  • 你好,

    请问guid列,是主键吗?

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年4月5日 6:42
    版主