开发者

Cast LINQ Function Result to Domain Object

开发者 https://www.devze.com 2022-12-31 03:58 出处:网络
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 addit

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.

S开发者_Go百科o, 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?


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.

:)

0

精彩评论

暂无评论...
验证码 换一张
取 消