【问题标题】:Specified type member is not supported in linq to entitieslinq to entity 不支持指定类型的成员
【发布时间】:2012-03-03 11:50:08
【问题描述】:

您好,希望有人能提供帮助。

我有一个 EF4 上下文,其中包含 2 个基于 POCO 的实体,这些实体映射到旧版 SQL2005 数据库中的 2 个表。表之间没有关系,上下文中的实体定义之间也没有关联。

public class Venue
{
    public Venue(){}
    public string LocationCode {get;set;}
    public string LocationName {get;set;}
}

public class Booking
{
    public Booking(){}
    public string LocationCode {get;set;}
    public int EventReference {get;set;}
    public Venue BookingVenue {get;set;}
    public Event BookingEvent {get;set;}
}

public class Event
{
    public Event(){}
    public int EventReference {get;set;}
    public DateTime EventStart {get;set;}
    /* plus another 60 or so properties */
}

我可以分别从每个选项中进行 LINQ 选择,但每当我尝试在 Event 和 Booking 之间加入时,我都会得到 ​​p>

LINQ to Entities 不支持指定的类型成员“BookingEvent”。仅支持初始化器、实体成员和实体导航属性。

我已经尝试了所有可以在网络上找到的解决方法(没有枚举、计算属性等),现在我有点沮丧。

帮助? 这是有问题的查询....

List<Booking> bookings = (from b in CalendarDB.Bookings
    join e in CalendarDB.Events join b.EventReference on e.EventReference
    select b).ToList();

【问题讨论】:

  • 您能显示相关连接的代码吗?

标签: linq entity-framework join member


【解决方案1】:

如果没有模型中的关系,我认为 EF 无法弄清楚要使用哪些数据来加入。即使您的 Booking 类具有 BookingEvent 属性,EF 也不只是“知道”它需要基于 Booking.EventReference 加入 Event 表。因此,任何尝试使用这些引用属性的查询都会失败。

【讨论】:

  • 对不起,我应该给出一个 LINQ 查询的例子,它很简单。我已将其包含在原始问题中,您可以看到它只是手动加入。
猜你喜欢
  • 2015-01-27
  • 2012-07-17
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-28
  • 2018-02-19
相关资源
最近更新 更多