How to Fill TreeView from DataBase
I have a table(Hesab) whit 3 fields (ID,Name,FatherID), and use EF.

ID fatherID Name

1 NULL A

2 NULL B

3 2 C

4 1 D

5 4 E

6 4 F

7 3 G

8 1 H
 
and i want fill this table in treeview
 
the tree must be fill like this
A
-D
--F
--E
-H
B
-C
--G

I Created this class
   
       class Hesabs:Hesab
        {
        public Hesabs()
        {
            AllHesab = new ObservableCollection<Hesab>();
        }
        public ObservableCollection<Hesab> AllHesab { get; set; }
               }
and ViewModel

         public ObservableCollection<Hesabs> AllHesab { get; set; }
        public ObservableCollection<Hesabs> FirstHesab { get; set; }

        public ViewModelHesabs()
        { 
            CRMEntities crm=new CRMEntities();

            var ls = from h in crm.Hesab
                     where (h.FatherID == null)
                     select h;
            ObservableCollection<Hesabs> hes = new ObservableCollection<Hesabs>();
            foreach (Hesab hh in ls.ToList())
            {
                var ls2 = from h in crm.Hesab
                          where (h.FatherID == hh.ID)
                          select h;
                Hesabs hesab = new Hesabs();
                hesab.Name = hh.Name;
                hesab.ID = hh.ID;
                hesab.AllHesab = new ObservableCollection<Hesab>(ls2.ToList());
                hes.Add(hesab);
            }
            FirstHesab = hes;
        }
and xaml

            <TreeView ItemsSource="{Binding FirstHesab}">
            <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding AllHesab}" DataType="         {x:Type local:Hesabs}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}"  Tag="{Binding ID}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

**but fill 2 level :(**
How to Fill TreeView from DataBase
===

I have a table(Hesab) whit 3 fields (ID,Name,FatherID), and use EF.

ID fatherID Name

1 NULL A

2 NULL B

3 2 C

4 1 D

5 4 E

6 4 F

7 3 G

8 1 H
 
and i want fill this table in treeview
 
the tree must be fill like this
A
-D
--F
--E
-H
B
-C
--G

I Created this class
   
       class Hesabs:Hesab
        {
        public Hesabs()
        {
            AllHesab = new ObservableCollection<Hesab>();
        }
        public ObservableCollection<Hesab> AllHesab { get; set; }
               }
and ViewModel

         public ObservableCollection<Hesabs> AllHesab { get; set; }
        public ObservableCollection<Hesabs> FirstHesab { get; set; }

        public ViewModelHesabs()
        { 
            CRMEntities crm=new CRMEntities();

            var ls = from h in crm.Hesab
                     where (h.FatherID == null)
                     select h;
            ObservableCollection<Hesabs> hes = new ObservableCollection<Hesabs>();
            foreach (Hesab hh in ls.ToList())
            {
                var ls2 = from h in crm.Hesab
                          where (h.FatherID == hh.ID)
                          select h;
                Hesabs hesab = new Hesabs();
                hesab.Name = hh.Name;
                hesab.ID = hh.ID;
                hesab.AllHesab = new ObservableCollection<Hesab>(ls2.ToList());
                hes.Add(hesab);
            }
            FirstHesab = hes;
        }
and xaml

            <TreeView ItemsSource="{Binding FirstHesab}">
            <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding AllHesab}" DataType="         {x:Type local:Hesabs}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}"  Tag="{Binding ID}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

**but fill 2 level :(**