I am not sure why the following does not return a value for Vend as a string .
When I check for the value of vend it says: System.Data.Objects.ObjectQuery``1[System.String]
string vend = (from vnd in db.Vendors
where vnd.VendorID == id
select vnd.VendorName).ToString();
When I view the value of vend, it is not what I expected
You are getting an
IQueryable<String>back from you query. You need either the First or Single or something:The
ToStringis not need ifVendorNameis a String.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.