开发者

problem with converting the output from linq query to string

I'm sorry to ask this basic question,

var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath);

I want to convert the output to string.

I tried these things:

string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).ToString();

and

 var filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp开发者_开发技巧1.FilePath);
        string filePathInString = filePath.ToString();

both times i'm getting error:

Linq.Internals.UnoptimizedQuery<string>

Please help me out

How should i solve this problem ?

PS: If some one thinks this question is stupid or for some reason does not like it. U may delete this question after getting answered instead of flagging or down voting it


Try changing the query to

string filePath = (from Component comp1 in componentContainer where comp1.ComponentName == fileName select comp1.FilePath).FirstOrDefault().ToString();


string filePath=componentContainer.Single(x=>x.ComponentName==fileName).FilePath;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜