使用.Include和继承 [英] Using .Include with inheritance

查看:107
本文介绍了使用.Include和继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用带有继承类的.Include命令时遇到了麻烦。

解决方案

如果我可以重复我认为你在说什么(在我自己的话语与我自己的情景)。

场景:
我有两个EntityTypes:Car和SportsCar(源自Car),我有一套名为"Cars"的东西。
Car一个名为"制造商"的导航属性

SportsCar有一个名为"Spoiler"的导航属性。

鉴于此场景,我认为*这个:

context.Cars.Include( "Spoiler")l

是不可能的,因为有些汽车不能有一个Spoiler。

但是我怀疑这是可能的:

context.Car .OfType< SportsCar>()。包括("Spoiler");

我将为您确认两种方式






I am having trouble using .Include commands with inherited classes.

解决方案

If I can repeat what I think you are saying (in my own words with my own scenario).

Scenario:
I have two EntityTypes: Car and SportsCar (which derives from Car) and I have one set called "Cars".
Car has a navigation property called "Manufacturer"
SportsCar has a navigation property called "Spoiler".

Given this scenario then I *think* this:

context.Cars.Include("Spoiler")l
 
is impossible, because some of the cars can't have a Spoiler.

However I suspect this would be possible:

context.Car.OfType<SportsCar>().Include("Spoiler");

I will confirm either way for you
Cheers
Alex


这篇关于使用.Include和继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆