views:

45

answers:

4

Hi I'm doing a little report using subsonic I'm pretty noob And I can't figure how to list only the first record in my report I'm doing something like:

new Select("id,Name,place,group").From(User.Schema)
                                 .InnerJoin(Profile.Schema)
                                 .InnerJoin(userGroup.Schema)
                                 .Where("place")
                                 .IsEqualTo("insomeplace")
                                 .ExecuteReader();

    result:
    093007 Joe doe insomeplace S2A
    093007 Joe doe insomeplace S2A
    093007 Joe doe insomeplace S2A
    093007 Joe doe insomeplace S2A

I have try to new Select("bla bla").Distinct() new Select("bla bla").Top("1") but none of those appear to work... so what I can do??? any ideas???

When used Top("1") I got a error saying "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1user.id, user.Name, Place, Place FROM user ' at line 1"

I'm using subsonic 2.x

thanks in advance

A: 

quit!!!! I proffered use of

string sqlString = "Select * ...";
new InlineQuery().ExecuteReader(sqlString);
ncubica
A: 

I'm assuming from the reference in your question that you are using MySql. I'm afraid that I don't know much about MySql, but the following may be helpful:

  1. I can assure you that .Top("1") certainly works in SubSonic 2.x against SQL Server.
  2. Can you find an equivalent to SQL Server's Profiler for MySql to see what SQL code is being sent to the database?
  3. TOP 1 isn't valid SQL in MySql, instead you need to use the LIMIT clause - http://dev.mysql.com/doc/refman/5.0/en/select.html
kevinw
Thanks....!!! what I did is use group by and the InlineQuery Method to resolved the problem...
ncubica
A: 

You can use the Paged(...) method:

new Select("id,Name,place,group").From(User.Schema)
                                 .InnerJoin(Profile.Schema)
                                 .InnerJoin(userGroup.Schema)
                                 .Where("place")
                                 .Paged(1, 1)
                                 .IsEqualTo("insomeplace")
                                 .ExecuteReader();

I'm not 100% percent sure if you have to use Paged(1,1) or Paged(0,1), try both.

SchlaWiener
thanks for the answer and your time, I will try you example, what I did to resolved my issue in the past days was this:string sqlPlacesNull = "Select Name, Place, u.Id FROM users u JOIN user_place_group amg on u.Id = amg.Id JOIN Profile p on u.Id = p.Id WHERE place IS NULL AND p.group = 'S' group by u.Id";gv.DataSource = new InlineQuery().ExecuteReader(sqlPlacesNull);gv.DataBind();
ncubica
what I used is Group By and What I been read is that .Top works for older version of 2.x subsonic... I hope change to 3.0 in the incoming months... thanks again...
ncubica
You can use Group By with subsonic too: `new Select(SubSonic.Aggregates.GroupBy("id"), SubSonic.Aggregate.GroupBy("name"), ...).From(...)` http://jamesewelch.wordpress.com/2008/07/03/how-to-perform-an-aggregate-query-using-subsonic-21s-sqlquery/
SchlaWiener
oohh nice didn't know it... but yesterday I grab my new copy of VS 2010 soooo... is subsonic 3.x time ;) thanks for the support
ncubica
A: 

Another way to do this would be to use .ExecuteSingle(), which would return only the first result. The downside of this is that the database would actually return all rows of the query (SubSonic simply discards anything but the first record).

ranomore
I guess you have a better option here... thanks for the time
ncubica