var vehicles = (from vehicle in DB.Vehicles
join brand in DB.VehicleBrands on vehicle.BrandId equals brand.Id into data_b from b in data_b.DefaultIfEmpty()
join model in DB.VehicleModels on vehicle.ModelId equals model.Id into data_m from m in data_m.DefaultIfEmpty()
join type in DB.VehicleTypes on vehicle.TypeId equals type.Id into data_t from t in data_t.DefaultIfEmpty()
where
(brandId == null || vehicle.BrandId == brandId) &&
(modelId == null || vehicle.ModelId == modelId) &&
(typeId == null || vehicle.TypeId == typeId) &&
(priceMin == null || vehicle.Price >= priceMin) &&
(priceMax == null || vehicle.Price <= priceMax) &&
vehicle.IsDeleted == false && vehicle.IsActive == true && vehicle.IsSold == false
orderby vehicle.CreateDate descending
select new
{
vehicle.Id,
vehicle.Title,
b.BrandName,
m.ModelName,
vehicle.Price,
vehicle.CreateDate,
vehicle.PhotoPath
});
gvVehicle.DataSource = vehicles;
gvVehicle.DataBind();
linq : left join with linq
Gönderen
pantepember
7 Nisan 2010 Çarşamba