0

does anybody know if it’s possible to query an sql server with my own query?

I can't find any information, that I can get to work, so perhaps there is something else I'm missing?

I have tried a LOT of samples from different websites, so it's for the lack of trying (I'm new to ef (and ef core)) I would like to write a sql to call a database function that for some reason is not part of the database scaffolding I have added the following nuget packages (I don’t think I’m missing any?)

PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.6" />
PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="6.0.6" />
PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.6" />
PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.6">

I have run dotnet tool install --global dotnet-ef 
(Hours spend on scaffolding not working, before I ran that command)

I used the following to scaffold dotnet ef dbcontext scaffold "Data Source=myservername;Initial Catalog=mydbname; Persist Security Info=True;User ID=myuserid;Password='mypassword'" Microsoft.EntityFrameworkCore.SqlServer --output-dir Models

It generates fine into models folder But who do I write a "raw" query, so I can use the db function?

Aj.son
  • 13
  • 5
  • Does this answer your question? [Raw SQL Query without DbSet - Entity Framework Core](https://stackoverflow.com/questions/35631903/raw-sql-query-without-dbset-entity-framework-core) – Yong Shun Jul 04 '22 at 09:54

1 Answers1

0

This document describes how to configure EF to talk directly to a UDF.

See the section "Mapping a method to a SQL function"

  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](https://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. – cursorrux Jul 06 '22 at 12:10