Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call a stored procedure #6283

Closed
188 opened this issue Aug 10, 2016 · 10 comments
Closed

How to call a stored procedure #6283

188 opened this issue Aug 10, 2016 · 10 comments
Labels
closed-no-further-action The issue is closed and no further action is planned.
Milestone

Comments

@188
Copy link

188 commented Aug 10, 2016

How to call a stored procedure in EF core 1.0

@ajcvickers
Copy link
Member

@188 You probably want to use context.Database.ExecuteSqlCommand, or the FromSql method, which is documented here: https://docs.efproject.net/en/latest/querying/raw-sql.html

Please be more specific with your question if this information does not answer it.

@divega divega added the closed-no-further-action The issue is closed and no further action is planned. label Aug 10, 2016
@divega divega closed this as completed Aug 10, 2016
@divega divega added this to the Discussions milestone Aug 10, 2016
@Vasim-DigitalNexus
Copy link

@188 if you want to map to a DbSet from a stored procedure use the fromSql function

Example:

var data = db.Set<SomeDbSetModel>().FromSql("yourStoredProcedure p0, p1").ToList();

@188
Copy link
Author

188 commented Aug 11, 2016

Thanks

@josepoma
Copy link

Hi @Vasimovic,@188

In this example :
var data = db.Set<SomeDbSetModel>().FromSql("yourStoredProcedure p0, p1").ToList();

If in the stored procedure there is no ID column, EFCore displays the error message:

The entity type "SomeDbSetMode" requires a key to be defined.

As you can fix this ?, because it can be procedures that do not need to return an ID column.

Jose Poma

@gdoron
Copy link

gdoron commented Aug 28, 2016

It's currently not supported for FromSql to returned a not mapped CLR entity :(

@Vasim-DigitalNexus
Copy link

Vasim-DigitalNexus commented Aug 29, 2016

As @gdoron said currently not supported, I believe support will be added in 1.1.0 release (Edited: changed 1.0.1 to 1.1.0 as per @divega )

If possible you could try adding [Key] to one of the columns and use the AsNoTracking() for now

var data = db.Set<SomeDbSetModel>().AsNoTracking().FromSql("yourStoredProcedure p0, p1").ToList();

@divega
Copy link
Contributor

divega commented Aug 29, 2016

@Vasimovic FWIW the feature at #1862 is planned for 1.1.0, not 1.0.1. The latter is a patch release containing a few high priority bug fixes.

@gdoron
Copy link

gdoron commented Aug 29, 2016

@divega Since the versions thing was discussed.
Do you know:

  1. When is the release date of 1.0.1, it was said to be ~Auguest, which ends in 2 days.
  2. Is there going to be a preview release of 1.1.0 just like there was with RC1+2?
    If the answer is yes, do you know when?

Thanks Diego!

@divega
Copy link
Contributor

divega commented Aug 29, 2016

@gdoron I don't have specific dates to share, but 1.0.1 will ship soon, and yes, there will be preview releases of 1.1.0.

cc @Eilon in case he can share specific dates.

@Eilon
Copy link
Member

Eilon commented Aug 30, 2016

@gdoron we were initially planning to do 1.0.1 in August but for a variety of reasons we had to delay it - currently planned for September. You can already get the pre-release patched bits here: https://dotnet.myget.org/gallery/aspnetcore-patch .

For 1.1.0 there will definitely be previews before 1.1.0 RTM. We're working on finalizing the dates, but expect something in ~1 - 1.5 months.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

7 participants