简体   繁体   English

使用Entity框架返回所有IQueryable

[英]return all IQueryable with Entity framework

I just switched from Linq to entities framework, and I'm having problems with methods that returns "all rows". 我刚刚从Linq切换到实体框架,我遇到了返回“所有行”的方法的问题。 I get: "The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced" error in my "service layer" that calls the data-layer. 我得到:“类型'System.Data.Objects.DataClasses.EntityObject'是在未引用的程序集中定义的”我的“服务层”中调用数据层的错误。

I get an error on: 我收到错误:

BookingObjectRepository _repository = new BookingObjectRepository();

public IQueryable<BookingObject> GetBookingObjects()
{
    return _repository.GetBookingObjects();
}

and in the "data-layer" I have: 在“数据层”我有:

BookingsystemEntities _entities = new BookingsystemEntities();

public IQueryable<BookingObject> GetBookingObjects()
    {
        return from bo in _entities.BookingObjectSet
               select bo;
    }

UPDATE: Filter items, they are "physically" in Filters-folder but namespace is same as the emdx file uses. 更新:过滤项目,它们“物理”在Filters-folder中,但名称空间与emdx文件使用的相同。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 

namespace BookingSystem.Data.Models
{

public static class BookingObjectFilters
{public static IQueryable<BookingObject> ByBookingObjectID(this IQueryable<BookingObject> qry, int bookingobjectID)
{
return from bo in qry
               where bo.BookingObjectID == bookingobjectID
               select bo;
}

Do you have 你有

using System.Data;
using System.Data.Objects.DataClasses;

in your usings? 在你的使用?

and

public IQueryable GetBookingObjects() { return _repository.GetBookingObjects(); } 

should probably be 应该是

public IQueryable<BookingObject> GetBookingObjects() { return _repository.GetBookingObjects(); } 

Hope that helps, 希望有所帮助,

Dan

您的系统必须安装.NET 3.5 SP 1或更高版本, 并且您的项目必须引用System.Data.Entity程序集(查看解决方案资源管理器中的references节点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM