开发者

ObjectSet and ResultSet on stored procedure on EF and Domain Service

开发者 https://www.devze.com 2023-01-07 18:00 出处:网络
In EF 4, the default ObjectSet is available for each entity. For example, I have table Employee, after gererated Entity Model, EF will create ObjectSet on Employee.

In EF 4, the default ObjectSet is available for each entity. For example, I have table Employee, after gererated Entity Model, EF will create ObjectSet on Employee. Then when using wcf ria service, the default query will be like:

public IQueryable GetEmployee() { return this.ObjectContext.Employees; }

With objectSet, I can apply include on the result like:

    return this.ObjectContext.Employees.Include("Department");

Then I create a stored procedure say MySearchForEmployee and import it as function. the result is mapped to entity Employee. When call the function, the result will be ResultSet, not ObjectSet.

I want to similar method available for domain service by call the stored procedure like:

   public IQueryable<Employeer> GetMySearch(string keyword)
        {
            return this.ObjectContext.MySearchForEmployee(keyword).Include("Department");
        }

But I can't becuase above code event can't pass syntax checking.

I tried f开发者_开发问答ollowing way to convet the result type:

 var results = this.ObjectContext.MySearchForEmployee(keyword);
 var objsets = (ObjectSet<Employee>) results;

then I got error as: Cannot convert type 'System.Data.Objects.ObjectResult' to 'System.Data.Objects.ObjectSet'

How to implement this request?


There is no reason to use an ObjectSet, because you cannot include multiple entity sets in one query from a stored procedure. This is not supported in the Entity Framework.

You could try the EFExtensions project, it has extensions to load multiple entity sets from one query.

0

精彩评论

暂无评论...
验证码 换一张
取 消