TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ramy Atef
NA
58
498
C# stored procedure with dynamic select values an Calling using Entity
Feb 3 2021 9:08 AM
I want to make a stored procedure to filter by passing columns and conditions in run time
t use this code this run but when i calling by Entity FrameWork must passing all columns in table to run but I do not like this i want to select a column different every executes how do this?
```ALTER proc [dbo].[spDynamicFilteration](
@ColumnsNames nvarchar(MAX),
@Conditions nvarchar(MAX)=null)
as
begin
EXEC ('select '+@ColumnsNames+' from TableName where ' +@Conditions+' ')
return
end ```
Calling by EF i used this
``` string data = "Id,TunnelId,VehicleTypedId,CategoryId,TotalCash,VisaCount,TunnelId,ShiftId,Date,LaneId,TotalCash,CashCount,TotalVisa,VisaCount";
string a = "ShiftId = 1 And Id = 78";
var d = entities.Filteration(data, "Id = " + a).FirstOrDefault();```
and this ` var orders = entities.Database.SqlQuery<PaidReport>("EXEC spDynamicFilteration {0},{1}", data, a).FirstOrDefault();
`
but stale same problem required all columns in table pass to run
Reply
Answers (
7
)
How to handle these errors?
How to display folder structure in tree view using ado.net mvc