User-707554951 posted
Hi roelofw,
After download your project, and open it in vs. and try to fetch data from database

Now it works well as below:
MegaChallengeEntities1 Class:
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class MegaChallengeEntities1 : DbContext
{
public MegaChallengeEntities1()
: base("name=MegaChallengeEntities1")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Price> Prices { get; set; }
}
}
PriceRepository.cs:
public class PriceRepository
{
public List<Price> GetCustomers()
{
using (MegaChallengeEntities1 db = new MegaChallengeEntities1())
{
var dbPrices = db.Prices;
var dtoPrices = new List<Price>();
foreach (Price dbPrice in dbPrices)
{
var dtoPrice = new Price();
dtoPrice.PriceId = dbPrice.PriceId;
dtoPrice.ProductName = dbPrice.ProductName;
dtoPrice.ProductPrice = dbPrice.ProductPrice;
dtoPrices.Add(dtoPrice);
}
return dtoPrices;
}
}
Test.aspx:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
CodeBehind:
protected void Page_Load(object sender, EventArgs e)
{
PriceRepository pro = new PriceRepository();
//MegaChallengeEntities1 db = new MegaChallengeEntities1();
//var dbPrices = db.Prices.ToList();
GridView1.DataSource = pro.GetCustomers();
GridView1.DataBind();
}
Output:

Best regards
Cathy