0
The following. I created a context class inherited from DbContext
.
public class SiloContext : DbContext
{
public SiloContext()
: base("inetConn")
{
}
public DbSet<Produto> Produtos { get; set; }
public DbSet<Balanca> Balancas { get; set; }
}
Well, then I created another class to load the Product information, based on the Context class.
public class ListaProdutos
{
private SiloContext contexto = new SiloContext();
public List<Produto> listaProdutos()
{
var prod = // O que colocar aqui? Tentei linq e nada, count == 0 e existe registros no banco.
//return prod;
}
}
If the above class works, then in the form at the click of the button, you should click or a Listbox, a Grid and etc...
I changed my model for it and it worked, but Linq takes the credit, so I scored his response.
[Table("Produto")]
public class Produto
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int idProduto { get; set; }
public string NMProduto { get; set; }
}
I’ve done it and Count is still 0.
– pnet
Then it is because there is no data @pnet
– Jéf Bueno
Just answer me this: In my model, I need to report something, like, map the table or just get;set;? If that’s it, something is missing. I just did the model, the get and set.
– pnet
At first you don’t need it. What is the name of the database table? It was generated by EF as well?
– Jéf Bueno
No, the bank already existed. Do a mapping, I think it’s right, okay? With Fluent or similar. If yes, this mapping I do in another mapping class, am I right? And not in the model.
– pnet
How is the table name of the database?
– Jéf Bueno
Product, this is the name of the table
– pnet
On top of the class name
Produto
place an attribute like this[Table("Produto")]
. Will need to add namespaceSystem.ComponentModel.DataAnnotations.Schema
– Jéf Bueno