Entity Framework Core retrieve single object from table

ef-database-first entity-framework-core

Question

I am trying to retrieve a single row from my table using Entity Framework core. This seems to be very simple, but i cannot get it to work.

I am able to get the list by using

_context.COUNTRY.ToList();

This gives me the full list of countries in my table. Now I need to get only one country that matches the ID. How to do this as Find() is missing in the EF core. Can we do a SELECT with WHERE. Can someone help me with the syntax.

My COUNTRY model is as shown below

public partial class COUNTRY { public string COUNTRYID { get; set; } public string COUNTRYNAME { get; set; } }

1
1
6/14/2016 7:48:08 PM

Popular Answer

This worked

_context.COUNTRY.Single(c => c.COUNTRYID == id);

1
6/14/2016 7:59:18 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow