views:

73

answers:

1

Hello, I have a table valued function to perform full text search on SQL server.

The result type of my full text search function in LINQ is a special autogenerated type which includes KEY and RANK in addition to my regular domain object properties.

So, if my regular domain object is PERSONS (with properties FirstName, LastName etc.), I also have a result object PERSONS_FTSResult with the same properties + KEY and RANK.

Is there an easy way to cast it back to PERSONS?

+1  A: 

Couldn't you do something like this:

var x = from data in searchResults
        select new {
            key = data.Key,
            rank = data.Rank,
            person = new Person { firstName = data.FirstName }
                    };

Person p = x.First().person;

I apologize if a bit of the syntax is bad, but I'm playing Eve Online, not coding right now.

:)

Robaticus
Sorry I can't figure this out. Can you check this code please?
Alex
You said that your search results would contain all of the members of Person, plus Key and Rank. The LINQ above selects a new anonymous type that consists of all of the data, and initializes it appropriately. The first two things it puts in the type are key, and rank. Then it creates a new instance of Person, and initialize it with the result set. Looking at it, I did notice one issue, the right hand side of the assignment should have the word "data" prepended to them. I'll edit.
Robaticus