sql - EF CodeFirst TPH does not produces Inner Join? -


simple linq include produce huge sql code left outer join instead of inner join.

i suppose see inner join because 2 tables connected via foreign key , column transportpointid not null.

any ideas how force ef use inner join in case?

var stops = context.transportobjects.oftype<stop>()                                     .include(s => s.points).tolist(); 
select   [project1].[transportobjectid]  [transportobjectid],          [project1].[type]               [type],          [project1].[name]               [name],          [project1].[internalname]       [internalname],          [project1].[c1]                 [c1],          [project1].[type1]              [type1],          [project1].[transportpointid]   [transportpointid],          [project1].[transportobjectid1] [transportobjectid1],          [project1].[name1]              [name1],          [project1].[standname]          [standname]     (select [extent1].[transportobjectid] [transportobjectid],                  [extent1].[name]              [name],                  [extent1].[internalname]      [internalname],                  [extent1].[type]              [type],                  [extent2].[transportpointid]  [transportpointid],                  [extent2].[transportobjectid] [transportobjectid1],                  [extent2].[name]              [name1],                  [extent2].[standname]         [standname],                  [extent2].[type]              [type1],                  case                     when ([extent2].[transportpointid] null) cast(null int)                    else 1                  end [c1]             [centraldatabase].[transportobjects] [extent1]                  left outer join [centraldatabase].[transportpoints] [extent2]                    on ([extent2].[type] in (cast('2' smallint),cast('1' smallint)))                       , ([extent1].[transportobjectid] = [extent2].[transportobjectid])            [extent1].[type] in (cast('1' smallint),cast('2' smallint))) [project1] order [project1].[transportobjectid] asc,          [project1].[c1] asc 

model

public enum transportobjecttype : short {     stop = 1,     referenceobject = 2 }  public abstract class transportobject {     public int transportobjectid { get; set; }     public string name { get; set; }     public virtual list<transportpoint> points { get; set; } }  public class stop : transportobject {     public string internalname { get; set; } }  public enum transportpointtype {     stoppoint = 1,     referencepoint = 2 }  public abstract class transportpoint {     public int transportpointid { get; set; }     public int transportobjectid { get; set; }     public virtual transportobject transportobject { get; set; }     public string name { get; set; } }  public class stoppoint : transportpoint {     public string standname { get; set; } } 

mapping (just important parts)

public class transportobjectmap : entitytypeconfiguration<transportobject> {     public transportobjectmap()     {         this.map<stop>(m => m.requires("type").hasvalue((short)transportobjecttype.stop))             .map<referenceobject>(m => m.requires("type").hasvalue((short)transportobjecttype.referenceobject));     } }  public class transportpointmap : entitytypeconfiguration<transportpoint> {     public transportpointmap()     {         this.map<stoppoint>(m => m.requires("type").hasvalue((short)transportpointtype.stoppoint))             .map<referencepoint>(m => m.requires("type").hasvalue((short)transportpointtype.referencepoint));          // add not nullable fk         this.hasrequired(o => o.transportobject)             .withmany(p => p.points)             .hasforeignkey(p => p.transportobjectid);     } } 

database correct.

db

i think needs left outer join because if have transportobject without transportpoint, transportobject wont included in result, , according linq query want transportobjects in list.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -