我正在执行一项性能改进任务以优化 LINQ-SQL 查询逻辑。有人可以建议最佳优化查询。这是我的查询
var localResponse = (from p in context.Places
where (p.PlaceName.Contains(searchText))
&& (p.MkTypeId == MkType.Premise)
&& p.PlaceName != null
&& p.ObjectState != ObjectState.Deleted
select new Prediction {
value = p.PlaceName,
id = p.APIPlaceId,
reference = p.APIPlaceReference,
latitude = p.Location.Latitude,
longitude = p.Location.Longitude,
addressId = p.AddressId,
bedroom = p.Bedroom,
placeTypeId = p.PlaceTypeId,
placeId = p.Id
})
.Union(from p in context.Places
join cp in context.Places on p.Id equals cp.ParentPlaceId
where (p.PlaceName.Contains(searchText) || cp.PlaceName.Contains(searchText))
&& (p.MkTypeId == MkType.Premise || p.MkTypeId == MkType.Room)
&& p.PlaceName != null
&& cp.PlaceName != null
&& p.ObjectState != ObjectState.Deleted
&& cp.ObjectState != ObjectState.Deleted
select new Prediction {
value = cp.PlaceName + ", " + p.PlaceName,
id = p.APIPlaceId,
reference = p.APIPlaceReference,
latitude = p.Location.Latitude,
longitude = p.Location.Longitude,
addressId = p.AddressId,
bedroom = p.Bedroom,
placeTypeId = p.PlaceTypeId,
placeId = p.Id });
这是预测类
public class Prediction
{
public string id { get; set; }
public string reference { get; set; }
public string value { get; set; }
public double? latitude { get; set; }
public double? longitude { get; set; }
public int? addressId { get; set; }
public int? bedroom { get; set; }
public PlaceType placeTypeId { get; set; }
public int? placeId { get; set; }
}
提前致谢