Getting single result from a query with anonymous types in Linq To Sql?

Var singleResult = result.Single(); string name = singleResult. CustomName; // etc Furthermore, each time you call Single() it will execute the query. You should grab the value once and use it wherever you need.

As long as you use var you should be fine, you just can't return that anonymous type from a method.

Var singleResult = result.Single(); string name = singleResult. CustomName; // etc... Furthermore, each time you call Single() it will execute the query. You should grab the value once and use it wherever you need.

As long as you use var you should be fine, you just can't return that anonymous type from a method.

You can say var result = (from row in db. Table select new { CustomName = row. RowName }).Single(); string name = result.

CustomName; // etc. But probably the best way is to encapsulate your result into a bonafide non-anonymous class. Then you can say MyClass result = (from row in db. Table select new MyClass() { CustomName = row.

RowName }).Single(); string name = result. CustomName; // etc.Here you would have, for example, class MyClass { public string CustomName { get; set; } // etc. }.

You could try var result = (from row in db. Table select new { CustomName = row. RowName }).Single(); Then you can access your property with var foo = result.

CustomName; // etc.

Var result = (from row in db. Select new { CustomName = row. String name = result.

MyClass result = (from row in db. Select new MyClass() { CustomName = row. String name = result.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions