自引用模型类 - 如何使用实体框架填充 [英] Self Reference Model Class - How to populate using Entity Framework

查看:52
本文介绍了自引用模型类 - 如何使用实体框架填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server中有一个名为Employees的表,如下所示:

Hi,i have table in SQL Server named Employees as follows:

EmployeeId  lastName  FirstName  reportsTo

1  Davolio  Nancy  ; 2

2  Fuller  Andrew  NULL

3  Leverling  Janet  2

4  Peacock  Margaret  2&brbsp >
5  Buchanan  Steven  2

6  Suyama  Michael  5

7  King  Robert  5

8  Callahan  Laura  2

9  Dodsworth  Anne  5

EmployeeId lastName FirstName reportsTo
1 Davolio Nancy 2
2 Fuller Andrew NULL
3 Leverling Janet 2
4 Peacock Margaret 2
5 Buchanan Steven 2
6 Suyama Michael 5
7 King Robert 5
8 Callahan Laura 2
9 Dodsworth Anne 5

我想使用Entity填充我的Model Class的框架。我的模型类如下所示:

I would like to use Entity Framework to populate my Model Class .My model class looks as follows:

public class Employees

{

    ; readonly List< Employees> _children = new List< Employees>();

   公共IList<员工>儿童

    {

       得到{return _children; }
    }

public class Employees
{
    readonly List<Employees> _children = new List<Employees>();
    public IList<Employees> Children
    {
        get { return _children; }
    }

    public string FirstName {get;组; }
    public string LastName {get;设置;}

}

    public string FirstName { get; set; }
    public string LastName {get; set;}
}

我想在ViewModel中使用此类 填充我的TreeView控件。任何人都可以帮助我定义Linq to Entities,以便从定义的SQL Server中的表填充我的模型类Employees。提前致谢。

I want to use this class in ViewModel  to populate my TreeView control. Can anyone help me in order to define Linq to Entities in order to populate my model class Employees from table in SQL Server as defined. Thanks in advance.

Almir

推荐答案


查看此MSDN链接入门教程+代码示例
。别忘了bing / google!

please see this MSDN link for getting started tutorials + code samples. don't forget to bing / google!

希望这会有所帮助!


这篇关于自引用模型类 - 如何使用实体框架填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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