ASP.NET MVC Partial Model Binding from Stored Procedures -


Currently, I have a set of stored procedures that are asked to populate different fields on a page . I'm calling stored procedures from LINQ to SQL class, on which I left them, which works fine. However, it automatically generates (StoredProcedureName) name of the result class with whom I have to work.

Can anyone take a stored procedure and bind the result into several sections? For example, I have a stored procedure that gets information about blog posts. I want to pair that data into a post class and a user class (for the author), but I'm not retrieving all the data from the stored procedure to fill an entire post object or user object (the stored procedure only returns the headline Is the name of the content and author).

What is the best way to handle this scenario? I'm opening to change the stored procedure but I do not have to return that data. I'm not going to use to fully populate the object and I want to query from database to LINQ to SQL Can not use

You can partialize your datacentext and write a method that returns IMultipleResults, your related Compulsory for classes [ResultType (typeOf (ClassName)]], as shown here:

Or, you store the results of the stored procedure in a variable And then LINQ- choose new examples of your target classes in such a way:

  var results = dataContext.your_stored_proC (); Var Post = Results Select (S = & gt; New Post {id = Result. ID, Title = Results .title});  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -