c# - How do I join with OR condition? -


this linq code:

from b in dbcontext.sapbillofmaterials  t in dbcontext.auxcomponenttypes t.parentid == b.parent.id &&  t.materialtype == b.component.materialtype &&  (t.componentcategorycode == null || t.componentcategorycode == b.component.componentcategorycode)     select new     {       componentcode = b.component.model_componentcode,       grid = b.component.grid ,       componenttype = t.componenttype,       configurationid = configid,       parentskuid = b.parent.id ,       skuid = b.component.id       }; 

and linq entities translation:

    select      [extent2].[parentid] [parentid],      [extent4].[model_componentcode] [model_componentcode],      [extent4].[grid] [grid],      [extent2].[componenttype] [componenttype],      [extent1].[parent_id] [parent_id],      [extent1].[component_id] [component_id]        [dbo].[sapbillofmaterial] [extent1]     inner join [dbo].[auxcomponenttypes] [extent2] on [extent1].[parent_id] = [extent2].[parentid]     inner join [dbo].[sapmastermaterialsku] [extent3] on ([extent2].[materialtype] = [extent3].[materialtype])  , ([extent1].[component_id] = [extent3].[id])  **and ([extent2].[componentcategorycode] = [extent3].[componentcategorycode])**     left outer join [dbo].[sapmastermaterialsku] [extent4] on [extent1].[component_id] = [extent4].[id] 

so, it's totally ignoring or condition in join:

(t.componentcategorycode == null || t.componentcategorycode == b.component.componentcategorycode)

could tell me why or doing wrong?

update here simplified version of model:

public class auxcomponenttype {     [key]     public int id { get; set; }      [required, foreignkey("sapmastermaterialsku")]     public int parentid { get; set; }      public virtual sapmastermaterialsku sapmastermaterialsku { get; set; }      [required,stringlength(4)]     public string materialtype { get; set; }      [required, stringlength(1)]     public string componenttype { get; set; }      [required, stringlength(20)]     public string componentcategorycode { get; set; }  }  public class sapbillofmaterial {     [key, column(order = 1)]     public int id { get; set; }      [inverseproperty("sapbomchilds"), column(order = 2)]     public virtual sapmastermaterialsku parent { get; set; }      [inverseproperty("sapboms"), column(order = 3)]     public virtual sapmastermaterialsku component { get; set; }      public decimal quantity { get; set; }  }  public class sapmastermaterialsku {     [key]     public int id { get; set; }      [required,maxlength(18)]     public string model_componentcode { get; set; }      [maxlength(8)]     public string grid { get; set; }      [required,maxlength(4)]     public string materialtype { get; set; }       [required, maxlength(20)]     public string componentcategorycode { get; set; }      public virtual icollection<sapbillofmaterial> sapbomchilds { get; set; }     public virtual icollection<sapbillofmaterial> sapboms { get; set; }     public virtual icollection<auxcomponenttype> auxcomponenttypes { get; set; }  } 

is ever possible have auxcomponenttypes.componentcategorycode == null? field marked not nullable?


Comments