C
C#2y ago
barcode

❔ Mixing EF Core and another SQL library

Hello, I need to write some raw SQL queries outside the ORM but EF Core doesn't support that, how good is an idea of adding another SQL library to do those raw queries. It would be nice if I could split queries into seperate .sql files. Pls suggestions, thank you
15 Replies
barcode
barcode2y ago
I checked ADO.NET and it seems like what I'm looking for, is it a bad idea to have multiple db libs like this?
Angius
Angius2y ago
Dapper if anything But EF does let you execute raw queries
barcode
barcode2y ago
I saw Database.SqlQuery but it doesn't let me return objects only 1 scalar value as it says on docs Is there another way?
Angius
Angius2y ago
keyless entities
barcode
barcode2y ago
thx 😄 Hmm seems like [Keyless] creates the table, is this intended behavior?
Angius
Angius2y ago
It shouldn't be creating one
barcode
barcode2y ago
seems like adding Keyless annotation did nothing,
modelBuilder.Entity("rgm_api.Models.Keyless.Lala", b =>
{
b.Property<uint>("Lala1")
.HasColumnType("int unsigned");

b.Property<string>("Lala2")
.IsRequired()
.HasColumnType("longtext");

b.ToTable("Lalas");
});
modelBuilder.Entity("rgm_api.Models.Keyless.Lala", b =>
{
b.Property<uint>("Lala1")
.HasColumnType("int unsigned");

b.Property<string>("Lala2")
.IsRequired()
.HasColumnType("longtext");

b.ToTable("Lalas");
});
this is the result I get in my modelsnapshot and this is from msdn
modelBuilder
.Entity<BlogPostsCount>(
eb =>
{
eb.HasNoKey();
eb.ToView("View_BlogPostCounts");
eb.Property(v => v.BlogName).HasColumnName("Name");
});
modelBuilder
.Entity<BlogPostsCount>(
eb =>
{
eb.HasNoKey();
eb.ToView("View_BlogPostCounts");
eb.Property(v => v.BlogName).HasColumnName("Name");
});
seems like this issue exists for a while.. found github issues from 2018-2022
Angius
Angius2y ago
I guess it creates a view, then, huh I'd say go with Dapper, then
barcode
barcode2y ago
is it ok to mix ef core and dapper? no possible issues to arise?
Angius
Angius2y ago
Ideally, don't use them to query for the same things, but it should be fine
barcode
barcode2y ago
ty, using ef core to get and update 'simple' queries but I have some 60 liners that dapper will handle dapper works, gonna use it for selection and EF core for everything else, just feels wrong having 2 orms
BananaPie
BananaPie2y ago
I used 2 ORMs back in the old EF 4~6 days. The old EF was pretty slow on large reads. So I used dapper for that and EF for updating.
barcode
barcode2y ago
ty for info
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server