Linq Support Question,SELECT Single Colum

Topics: Developer Forum
Aug 28, 2008 at 7:48 AM

var list2 = from p in Site.Table where (p.Url == "http://www.codeplex.com/") select p.Url;

                foreach (var p in list2)
                {
                    Console.WriteLine(p);
                }

-----------------
the above code will return error

-----------------

var list2 = from p in Site.Table where (p.Url == "http://www.codeplex.com/") select p;

                foreach (var p in list2)
                {
                    Console.WriteLine(p);
                }
-----------------
the above code is right
-----------------

so I wanna generate the sql like

SELECT URL FROM xxxxx where...

I don't want select * FROM xxxxx where....

so How should i write the code with the linq or with "DBEntry.From...."

Coordinator
Aug 28, 2008 at 2:44 PM
Sorry, it's not supported for now.
I always write another class only have Url property and use it to get the data if the performance is very important.
Mar 3, 2009 at 9:50 AM
Is it supported now?
and What about Anonymous Type?
like
var r = from u in User.Table
           where u.id>100
           select new
            {
             Name=u.name
              }
Coordinator
Mar 3, 2009 at 10:42 AM
It's not supported.
And I don't think it's important since the most applications should not to care about such performance.
If it do just write another class will be fine.
Mar 3, 2009 at 11:04 AM
1, What does "write another class" mean, Many classes map the same table? Could you give a simple example?
2, Can "Using SQL statement" solve this problem?
Coordinator
Mar 3, 2009 at 2:47 PM
Yeah, many classes map the same table:

public class Site : DbObject
{
    public string Name;
    public string Url;
}

[DbTable("Site")]
public class SiteB : IDbObject
{
    public string Url;
}



And, use sql statement also works:
DataSet ds = DbEntry.Content.ExcuteDataSet("select url from site where id > 10");

Mar 3, 2009 at 3:01 PM
i see. thx!