My entity framework query is not returning any value. I wanted to replicate this query through entity framework: SELECT name FROM guitarBrands WHERE image = image. So I ended up trying this code below.
public static string GetBrandByImage(string imageType)
{
BrandsDBEntities obj = new BrandsDBEntities();
string name = (from g in obj.guitarBrands where g.image == imageType select g.name).ToString();
return name;
}
I'm really new at using entity framework and i really hope you guys can provide solutions for this.
null? Is it an empty string? Secondly, have you tried the same query with LINQ? (string name = (obj.Set<guitarBrands>().Where(g => g.image == imageType).Select( g => g.name).ToString();Thirdly, you should always useusingwith contexts:using( var obj = new BrandsDBEntities() ) { ... }. Finally, what version of EF are you using?