tags:

views:

102

answers:

2

Hi! I'm starting to do some test on SubSonic 3 and I'm missing some stuff.

1st: Where's the Table names constants? The place where we could ask for the same of a certain table using intelisense...

2nd: Same as the above but for the table columns... where are they? This is very useful mostly when you need to pass those names as string... it you need to refactor your DB we don't need to look through all the code to find where was I using that column!! Once you re-generate the code the compiler tells you!

3rd: Now how can I perform an ExecuteReader on a certain table like I'm used to on 2.x through the Query object? I used this a lot for list where I really don't need the business objects (BO) overhead... When I needed a BO (for showing a grid row details) I create it from the row itself...

I'm using ActiveRecord btw...

Thanks guys! Alex

A: 

1st and 2nd: It's not implemented in the default tt-files.

A similiar question: http://stackoverflow.com/questions/1110447/subsonic-3-simple-query-tool

Problem is that's not a correct implementation if you want the 2.x way - the XColumn properties used to be column objects and not string constants, those were found under the Columns struct. So I hope that check-in will not be accepted and that someone will 2.x-ify it correctly.

Anyway as you can see it seems pretty easy to fix it on your own.

Johan Kronberg
Ok... I thought I was missing something.Same thing for the Table names struct right?I guess I'll just modify the templates.What about the 3rd question?
AlexCode
I'm pretty sure someone committed the column names struct already. Should be in 3.0.0.3 templates.
John Sheehan
@John Yes it is in 3.0.0.3
Adam
+1  A: 

1st: Where's the Table names constants? The place where we could ask for the same of a certain table using intelisense...

In Structs.tt find the following line of code at line 47:

<#          foreach(var col in tbl.Columns){#>

Add the following code above it:

public static string TableName { get { return "<#=tbl.Name#>"; } }

Now you'll have a property that returns the name of the table.

2nd: Same as the above but for the table columns... where are they?

In the generated Structs.cs file, this is included in the 3.0.0.3 version

3rd: Now how can I perform an ExecuteReader on a certain table like I'm used to on 2.x through the Query object? I used this a lot for list where I really don't need the business objects (BO) overhead... When I needed a BO (for showing a grid row details) I create it from the row itself...

If you're using SqlQuery object you can call ExecuteReader on it. Alternatively you can use Linq syntax to generate return custom shaped objects and they'll get mapped automatically.

Adam