0
I took a test to do and it is mandatory to use Ado.Net, but it would be a differential the use of Entity. I’m a little confused about this. Ado.Net and Entity gives ball?
0
I took a test to do and it is mandatory to use Ado.Net, but it would be a differential the use of Entity. I’m a little confused about this. Ado.Net and Entity gives ball?
1
If the doubt is whether the two work together, yes the two can work together
Look at the example I put together
class Program
{
static void Main(string[] args)
{
InserirDados();
UsandoAdo();
UsandoEF();
}
static void InserirDados()
{
using (EFContext ef = new EFContext())
{
if (!ef.Pessoas.Any())
{
for (int i = 0; i < 10; i++)
{
ef.Pessoas.Add(new Pessoa() { Nome = $"Nome {i}" });
}
ef.SaveChanges();
}
}
}
static void UsandoAdo()
{
using (SqlConnection ado = new SqlConnection(ConfigurationManager.ConnectionStrings["EFContext"].ToString()))
{
string select = "select * from pessoas";
SqlCommand command = new SqlCommand(select, ado);
ado.Open();
var dr = command.ExecuteReader();
while(dr.Read())
{
Console.WriteLine($"Usando ADO {dr["Nome"]}");
}
}
}
static void UsandoEF()
{
using (EFContext ef = new EFContext())
{
foreach(var pessoa in ef.Pessoas.ToList())
{
Console.WriteLine($"Usando EF {pessoa.Nome}");
}
}
}
}
public class EFContext : DbContext
{
public DbSet<Pessoa> Pessoas { get; set; }
}
public class Pessoa
{
[Key]
public int Id { get; set; }
public string Nome { get; set; }
}
I added the example source code to my github
Browser other questions tagged c# entity-framework ado.net
You are not signed in. Login or sign up in order to post.
What do you mean, dance? Talk about wearing both in the same project?
– Pablo Tondolo de Vargas
I believe you are asking if the two work together and it is correct to do so, yes you can use, just dosar and know how to do but, it works smoothly, including many utlizar Entity and Dapper in the same application.
– novic
It’s a dance, man. But I don’t know.. I prefer to be with only one, there are people who use Dapper and EF as @Virgilionovic commented, I am particularly more adept at Dapper, when the thing gets complex in EF and you need to do maintenance in some query via Linq I prefer to tinker with SQL rather than head-banging with Line and syntax when you have huge relationships
– Thiago Loureiro