I have below data in database table "City" with no primary key
CityId CityName
1 ABC
1 XYZ
I am using entityframework to fetch this data and I am getting same row. Below is the Context Class code
public class StudentsDbContext :DbContext
{
public DbSet<City> cities { get; set; }
}
Below is the City Class Code
[Table("City")]
public class City
{
[Key]
public int CityId { get; set; }
public string CityName { get; set; }
}
Below is the output code
StudentsDbContext studentsDbContext = new StudentsDbContext();
List<City> cities = studentsDbContext.cities.ToList();
foreach (var val in cities)
{
Console.WriteLine("studentName: " + val.CityName);
}
Console.ReadLine();
Below is the output image enter image description here
Below is the desired result
CityName: ABC
CityName: XYZ