I got the error
cannot implicity convert type 'System.Linq.IQueryable<EntityNetimoveis.San_Imovel>' to 'EntityNetimoveis.San_Imovel' An Explicit conversion exists (are you missing a cast ?)
This occurs when I try the following code
EntityNetimoveis.San2011Entities db = new EntityNetimoveis.San2011Entities();
EntityNetimoveis.San_Imovel im = db.San_Imovel.Where(a => a.Credenciada_Id == 10);
What type of conversion I have to do ?
The type of im is an
IQueryable<EntityNetimoveis.San_Imovel>because you are running a where query and there might be more than one result. If you want the first result matching your query you should use .FirstOrDefault(). Try changing you code as:If you want to return more than one entity and process them, lets say using a foreach loop, then you need to change the type of the return value to
IEnumerable<Netimoveis.San_Imovel>. See the following example:The you can use the following: