从EF .sdf文件访问数据,没有edmx设计器内容

时间:2014-05-21 08:07:15

标签: c# .net wpf entity-framework entity

我不知道我是否创建了实体,但在我的解决方案中创建了EDMX文件。它没有表,因为我创建了一个新表,然后创建了包含表和数据(.SDF文件)的数据库。我想现在从表中检索数据。

第一个问题是,我不知道如何拖放它以使EDMX设计师不为空。

第二个也是最重要的是,我在下面的代码中收到错误,它说,"}"期待,但我看不到任何错误。

天才的人,请不要指出,功能没有回报,这是因为,我无法输入"返回'功能内部 - 奇怪。它说,在class / struct中是不允许的。

namespace Waf.BookLibrary.Library.Applications.Services
{
    class Service
    {
        public static IEnumerable<Student> GetAllStudents()
        {
        private ObservableCollection<Student> studentsList;

        public StudentEntities StudentEntities { get; set; }

        public ObservableCollection<Student> Students
        {
            get
            {
                if (studentsList == null && StudentEntities != null)
                {
                    StudentEntities.Set<Student>().Load();
                    studentsList = StudentEntities.Set<Student>().Local;
                }

                return studentsList;
            }
        }

        }   
    }
}

1 个答案:

答案 0 :(得分:2)

错误很容易被忽视,因为它非常出乎意料。您无法定义属性等 inside 方法。这就是结构应该是:

class Service
{
    private ObservableCollection<Student> studentsList;

    public StudentEntities StudentEntities { get; set; }

    public ObservableCollection<Student> Students
    {
        get
        {
            if (studentsList == null && StudentEntities != null)
            {
                StudentEntities.Set<Student>().Load();
                studentsList = StudentEntities.Set<Student>().Local;
            }

            return studentsList;
        }
    }

    public static IEnumerable<Student> GetAllStudents()
    {
        // Code here
    }   
}
相关问题