Left join w LINQ

var results = from c in db.CUSTOMER                         
                     join o in db.ORDER
                          on c.CustomerId equals o.CustomerId into joinedCustOrder
                          from order in joinedCustOrder.DefaultIfEmpty()
                      select new
                      {
                         Order = order,
                         Customer = c
                      };
Advertisements

Warunkowe dodanie kolumny do tabeli w bazie

IF NOT EXISTS (select * from sys.columns cols inner join sys.tables tabs on cols.[object_id]=tabs.[object_id] where tabs.type='U' and tabs.[name]='Trip' and cols.name='Description')
	alter table Trip ADD Description nvarchar(max)