linq toEntity 不支持指定的类型成员

发布于 2025-01-05 06:00:34 字数 1055 浏览 1 评论 0原文

嗨希望有人可以提供帮助。

我有一个 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 选择,但每当我尝试在“事件”和“预订”之间加入时,我都会得到

“指定类型成员“BookingEvent”在 LINQ to Entities 中不受支持”。仅支持初始值设定项、实体成员和实体导航属性。

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

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

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

Hi hope someone can help.

I have an EF4 context with 2 POCO based entities that map on to 2 tables in a legacy SQL2005 database. There are no relationships betwen the tables and no associations between the entity definitions in the context.

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

I can do a LINQ select from each individually but whenever I try and join between Event and Booking I get

The specified type member ‘BookingEvent’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

I've tried all the workarounds I can find across the web (there are no enums, calcualted properties, etc) and I'm more than a little frustrated now.

Help ?
Here's the query in question....

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱咩 2025-01-12 06:00:34

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

Without the relationships in the model, I don't think EF can figure out what data to use to join on. Even though your Booking class has a BookingEvent property, EF doesn't just 'know' that it needs to join on the Event table based on Booking.EventReference. Because of that, any query which attempts to use those reference properties will fail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文