Entity Framework returns 0 elements

I am using Entity Framework 6.1.3.

When I try to get the values ​​from the database table, it returns me 0 elements, but in the database - 9 rows.

And Entity FrameWork calls the OnModelCreating method.

I searched the entire Internet but found nothing to fix it.

My DbContext Class

namespace TestTask.Models
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class Entities : DbContext
    {
        public Entities()
            : base("MenuItemsContainer")
        { }

        protected override void OnModelCreating(DbModelBuilder modelBuilder) 
        { 

        modelBuilder.Properties() 
                    .Where(p => p.Name == "Id") 
                    .Configure(p => p.IsKey()); 
        } 

        public virtual DbSet<DataMenuItemSet> DataMenuItemSet { get; set; }
        public virtual DbSet<ItemsSet> ItemsSet { get; set; }
    }
}

My DataMenuItemSet Class

using System.ComponentModel.DataAnnotations;

namespace TestTask.Models
{
    using System;
    using System.Collections.Generic;

    public partial class DataMenuItemSet
    {
        public DataMenuItemSet()
        {
            this.ItemsSet = new HashSet<ItemsSet>();
        }

        [Key]
        public int Id { get; set; }
        public bool IsRoot { get; set; }
        public string Name { get; set; }
        public Nullable<int> Parent { get; set; }

        public virtual ICollection<ItemsSet> ItemsSet { get; set; }
    }
}

All this is created using the Entity Framework.

I need to get values ​​from a database.

Update

I solved the problem.

, . , , -, ConsoleApplication, . db dbcontext , , . , -, edmx dbcontext, , .

enter image description here

- ConsoleApplication - - dbcontext

enter image description here

Web.config Web.config App.cofig ConsoleApplication .

enter image description here

ConsoleApplication .

, .

!!!

+4
1

db LINQ.

using (var context = new Entities())
{
    var L2EQuery = from item in context.DataMenuItemSet
                   where item.IsRoot == true
                   select item;

    var result = L2EQuery.ToList()<DataMenuItemSet>;
 }

, .

0

Source: https://habr.com/ru/post/1599660/


All Articles