How to use FromSqlRaw, FromSqlInterpolated and ExecuteSqlRaw, ExecuteSqlInterpolated

Hi everybody!

I am developing an ASP.NET Core MVC app since .Net Core 1.0 and was happy to find LinqPad.

But there is one problem an i don't find any answer to this.

I want to use raw sql queries in LinqPad.

In VS it looks like this:
_context.Database.ExecuteSqlInterplated($"exec my_sp {myvar}");

I know that LinqPad creates a context for me, so i tried this:
TypedDataContext db = new TypedDataContext();
db.Database...

But, there is not "Database" method :-(

Can anyone tell me how to do this?

Comments

  • nescafe
    edited August 2020

    Use the built in ExecuteQuery<T> or ExecuteQueryDynamic function

    Or use int ExecuteCommand(string command, params object[] parameters) if your statement does not return data.

  • Also note that when you create the connection in LINQPad 6, you have the option of choosing EF Core instead of LINQ-to-SQL. If you choose EF Core, you'll be able to call this.Database.ExecuteSqlInterpolated.

  • Runs like a charm :-)
    Perfect. Thank you!

    @JoeAlbahari Thanks for LinqPad -> Really one of the best tools i know for developing in c#