Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从EF.sdf文件访问数据,但没有edmx设计器内容_C#_.net_Wpf_Entity Framework_Entity - Fatal编程技术网

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

C# 从EF.sdf文件访问数据,但没有edmx设计器内容,c#,.net,wpf,entity-framework,entity,C#,.net,Wpf,Entity Framework,Entity,我不知道是否创建了实体,但在我的解决方案中创建了一个EDMX文件。它没有表,因为我创建了一个新的表,然后使用表和数据(.SDF文件)创建了数据库。我现在想从表中检索数据 第一个问题是,我不知道如何拖放它,以便EDMX设计器不是空的 第二个也是最重要的是,我在下面的代码中得到了一个错误,它说,“}”expect,但我没有看到您看到的任何错误 天才们,请不要指出,函数没有返回,这是因为,我无法在函数中键入“return”-奇怪。它说,在类/结构中是不允许的 namespace Waf.BookLib

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

第一个问题是,我不知道如何拖放它,以便EDMX设计器不是空的

第二个也是最重要的是,我在下面的代码中得到了一个错误,它说,“}”expect,但我没有看到您看到的任何错误

天才们,请不要指出,函数没有返回,这是因为,我无法在函数中键入“return”-奇怪。它说,在类/结构中是不允许的

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;
            }
        }

        }   
    }
}
名称空间Waf.BookLibrary.Library.Applications.Services
{
班级服务
{
公共静态IEnumerable GetAllStudents()
{
私人可观察集合学生名单;
公共学生实体学生实体{get;set;}
公选学生
{
得到
{
if(studentsList==null&&studententies!=null)
{
StudentEntities.Set().Load();
studentsList=studententies.Set().Local;
}
返回学生名单;
}
}
}   
}
}

该错误很容易被忽略,因为它是非常意外的。您不能在方法内部定义属性等。这就是结构应该是什么:

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
    }   
}
类服务
{
私人可观察集合学生名单;
公共学生实体学生实体{get;set;}
公选学生
{
得到
{
if(studentsList==null&&studententies!=null)
{
StudentEntities.Set().Load();
studentsList=studententies.Set().Local;
}
返回学生名单;
}
}
公共静态IEnumerable GetAllStudents()
{
//代码在这里
}   
}

我已将代码从名称空间中正确放置,但由于可能存在一些对齐问题,此处未显示该代码。因此,专家们,请不要指出这一点。谢谢,将变量命名为与类(StudentEntities StudentEntities)完全相同并不合适。编译器可能也不喜欢。您不能将表拖放到edmx中。请选择“从数据库更新模型”“命令”。@supertopi:你确信这就是问题所在吗?在另一个来自互联网的解决方案中,它是有效的。@GertArnold:谢谢你,我做了,现在该怎么办?非常感谢你,Gert,我太傻了,但直到现在还不知道我们不能在方法中声明属性。再次感谢你。