SqlMethods class is only supported in LINQ to SQL queries. If you have to use this method, frist you have to add reference “System.Data.Linq.SqlClient.SqlMethods”. In LINQ to achieve the same thing, we have functions like StartsWith, EndsWith and Contains. SQL Methods, you can use those symbols exactly like SQL query.
Like statement in LInq entity framework and sqlMethod
public ActionResult Map()
{
//get loaction or latitude longitude according to databases
List<PushPinModel> pushPinCollection = new List<PushPinModel>();
pushPinCollection.Add(new PushPinModel { latittude = "43.4155817799037", longitude = "-123.345552938182", title = "tejjs", type = "Atm" });
pushPinCollection.Add(new PushPinModel { latittude = "44.0504273726889", longitude = "-121.354689398906", title = "help", type = "Atm" });
//linq to enity method
pushPinCollection.ToList().Where(p => p.title.StartsWith("t"));
pushPinCollection.ToList().Where(p => p.title.EndsWith("t"));
pushPinCollection.ToList().Where(p => p.title.Contains("t"));
// SqlMethods apply only on vlaues
pushPinCollection.ToList().Where(p => SqlMethods.Like( p.title,"t%"));
pushPinCollection.ToList().Where(p => SqlMethods.Like(p.title, "%t"));
pushPinCollection.ToList().Where(p => SqlMethods.Like(p.title, "%t%"));
ViewBag.data = pushPinCollection;
return View();
}
No comments:
Post a Comment