You are getting an IQueryable<String>
back from you query. You need either the First or Single or something:
string vend = (from vnd in db.Vendors
where vnd.VendorID == id
select vnd.VendorName).First().ToString();
The ToString
is not need if VendorName
is a String.
string vend = db.Vendors.Single(vnd => vnd.VendorID == id); // more terse
First will grab the first record from the set and will throw an exception if the set is empty.
FirstOrDefault will return the first record or the default for the type expected, no exception.
Single will return the first record of the set, but will throw an exception if there is more than one record in the set or if the set is empty.
SingleOrDefault will return the first record of the set or the default for the type if empty, but will throw an exception if there are more than one record in the set.