Calling CLR stored procedure [duplicate] - c#

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Invoking CLR stored procedures
Does anybody know how to call a CLR stored procedure using select statement?

As far as I know it's not possible without OPENQUERY or OPENROWSET, you'd better use CLR table function.
If you need to insert data from stored procedure
insert into Table
exec <your CLR procedure>

Related

How to make Microsoft Entity Framework 6.0 bulk update/delete faster? [duplicate]

This question already has answers here:
How to Bulk Update records in Entity Framework?
(9 answers)
Closed 2 years ago.
In my ASP.NET application I am using Entity Framework 6 with SQL Server. As per my scenario I need to perform a bulk update (40k row at a time) and bulk delete operation (40k row at a time) with EF6. EF6's RemoveRange method seems very very slow and update takes forever. Is there any way to speed this up?
you should try a stored procedure to delete the items, stored procedures are much faster and pre-compiled form stored in SQL Server.
for reference to work with Stored Procedure please visit the link.
Stored Procedure with Entity Framework

Get Last Inserted record Id Entity Framework [duplicate]

This question already has answers here:
Entity Framework and SCOPE_IDENTITY
(4 answers)
Closed 5 years ago.
I am inserting records in database using stored procedures like below
db.Database.ExecuteSqlCommand("sp_insertNewRecord");
Now I want to get the Id of last inserted record.
Due to some reason I can't use below function
db.TableName.Add(record);
db.SaveChanges();
So please don't suggest me to use this.
Create an output variable in your stored procedure like
create procedure [dbo].[Procedurename] #returnVal int output
as
SET #returnVal = SCOPE_IDENTITY();
After inserting the record get the SCOPE_IDENTITY() and set that into an OUTPUT variable.
and get the id in entity framework while calling stored procedure.
Hope this help!

Get returned value marked by RETURN from SP in Entity Framework C# [duplicate]

This question already has answers here:
Entity Framework - stored procedure return value
(5 answers)
Closed 5 years ago.
The problem is that many Stored Procedure must be return status code.
Which marked as
RETURN #status
so the EF (6.x) didn't recognize return type and SP call returns modified rows count (e.g 1,2 etc.)
The workaround to replace RETURN to SELECT is impossible
Change EF call to ADO.NET IMPOSSIBLE
So there is any workaround to get right value from SP without modifying SP
I am guessing you are using database approach. From the designer you can specify the return type of the stored procedure. Refer to this question here for more details how to do that.
Keep in mind that you wont need return part, just put in there select #status

How can I determine whether Stored Procedure Parameter is optional from C# code (I am using Sql Server) [duplicate]

This question already has answers here:
How can I determine if a SQL Server stored procedure parameter has a default?
(7 answers)
Closed 7 years ago.
I am using C# to connect to Sql Server. I am trying to get Parameter Details of stored procedure before calling the stored procedure. Can you please help me regarding how I can get to know whether any SP parameter is optional or not form C# code itself.
I am using loaclDb in VS 2013. I have Data Source and Db File Name available.
TIA.
You may do like this way:
Server servev = new Server("YourServerName");
Database dataBase = servev .Databases["YourDatabase"];
var paramData = dataBase.StoredProcedures["YourProcedureName"].Parameters;
foreach(StoredProcedureParameter param in param) {
string paramName=param.Name;
string paramValue=param.DefaultValue;
}

How to call a stored procedure that returns dynamic columns in Entity Framework? [duplicate]

This question already has answers here:
using stored procedure in entity framework
(6 answers)
Closed 9 years ago.
There is a stored procedure that executes exec command and returns some columns. Columns and number of them are varied. How can I call this stored procedure from Entity Framework?
You have to create a ComplexType in the EntityFramework and then call the stored procedure:
public ObjectResult<yourComplextype> MyMethod()
{
return _dbContext.usp_Yourprocedure();
}

Categories