Вопрос

I've followed this walkthrough to create a wcf+ef+self-tracking entities project.

Walkthrough: Serialize Self-Tracking Entities

In the Service, Linq to Entities can work well, but if I add a method which uses ESQL, for example:

public string Test()
    {
        string Name = "";

        string sql = "select  d.Name,d.Budget from SchoolEntities.Departments";
        using (SchoolEntities db = new SchoolEntities())
        {
            var query = db.CreateQuery<Department>(sql);
            if (query != null)
            {
                foreach (var v in query)
                {
                    Name = v.Name;               
                }
            }
        }
        return Name;
    }

An exception will be thrown when the code execution:

‘d.Name' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly.

Can anyone help?

Это было полезно?

Решение

I guess the problem is in the wrong ESQL query. You didn't declare what d is:

string sql = "SELECT d.Name, d.Budget FROM SchoolEntities.Departments AS d";

Also make sure that you select all fields mapped in department.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top