Jasmine
Jasmine

Reputation: 5326

Accessing data from EF .sdf file and no edmx designer contents

I don't know if I created Entity, but an EDMX file is created at my solution. It has no tables, because, I created a new one and then the database with table and data (.SDF file). I want to retrieve data from table now.

First problem is, I do not know how to drag and drop it so that EDMX designer is not empty.

Second and most important is, I get an error in the below code, it says, "}" expect, but I do not see any error as you can see.

Genius people, please don't point that, there is no return from function, it is because, I am unable to type "return' inside the function - Strange. It says, it is not permitted inside 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;
            }
        }

        }   
    }
}

Upvotes: 0

Views: 145

Answers (1)

Gert Arnold
Gert Arnold

Reputation: 109185

The error is easily overlooked because it's quite unexpected. You can't define properties etc. inside a method. This is what the structure should be:

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

Upvotes: 2

Related Questions