love your thoughts about it.
I am using jQuery autocomplete in an ASP.NET MVC application to retrieve a list of records from a database. I would like to know if there is a better way than how I am doing it now, as follows:
Here is jQuery (I call the GetRecordByName action method with autocomplete)
$('#tb_name').autocomplete({
source: 'Home/GetRecordByName',
minLength: 1, delay: 0,
select: function (event, ui) {
}
});
On the flip side, I use Linq for Entities in a method to retrieve results from a database:
public JsonResult GetRecordByName(string term)
{
var data = records
.Where(dr => dr.Key.StartsWith(term))
.Select(dr => new { dr, value = dr.Key })
.Take(5);
return Json(data, JsonRequestBehavior.AllowGet);
}
Currently it works a little slower (~ 1-2 seconds). Basically, a database has tens of thousands of records in it, and every time you enter a character in a text field, the application gets into the database. I can set it to 2 or 3 characters, but it does not change the speed, and I do not want to require a lot of characters.
, : pageload ( javascript) . , , - - ?
?
UPDATE:
, , , EF-. EF "" WHERE sql-; , linq - , , . Doh! .Where , , . , . ! , .
Flickr/ , /, , . OutputCache .
!