1

I have a stored procedure that returns a record like this (I simplified it)

SELECT 
    Id, FirstName, LastName, Father.FirstName, Father.LastName
FROM Profiles 
Left JOIN Profiles Father on Profiles.FatherId = Father.Id

I want this record to be returned as 2 properties of an object

var result = dataContext.StoredProcedure();
Profile = result.Profile;
Father = result.Father;

My question is, how do i take the single record

SELECT 
    Id, FirstName, LastName, Father.FirstName, Father.LastName

And split half of it to become one property/object (Profile), and the other half to become the other property/object (Father)

Reason For Using a Stored Procedure The actual sql statement includes a Full Text search, which is not supported in linq, so i cannot use a normal linq query.

2
  • why use a SP to achieve this? is it a real constraint from your db guy's or? Commented May 1, 2011 at 8:52
  • Because the actual statement uses full text search which isn't supported by linq. I just simplified the code Commented May 1, 2011 at 15:13

2 Answers 2

2

If I understand your problem correctly, you need two strongly typed objects, 'Profile' & 'Father' from your SQL result set. I see two options to do this;

1> Get your results as is from the stored proc and create your objects as stated below;

Profile p = new Profile P { Id=result.Id, FirstName= result.FirstName, LastName=result.LastName}; 
//and similar code for creating the 'Father' object

2> In your stored proc, get the results in a table variable first and then select two results from this table variable, first one 'Profile', second 'Father'. Your LINQ to SQL method calling the stored proc should be set to allow multiple result-sets. You can then access the results like;

Profile = result.Profile;
Father = result.Father;
Sign up to request clarification or add additional context in comments.

Comments

0
  • Create strongly-type object with 2 properties: Profile, Father
  • Create a navigation property Father for Profile object, so receiving Profile a consumer could easy navigate to Father

1 Comment

I suppose this is a suggestion to remove the sp and use linq instaed. This isn't an option as I explained in the comments at the original question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.