Hanalei, Hawaii Monday, February 08, 2010

SubSonic 3: Alpha Is Ready

SubSonic 3 is ready for Alpha. It's a pretty significant upgrade and I think I've tackled all the bugs and issues.

SubSonic 3 is ready for Alpha. It's a pretty significant upgrade and I think I've tackled all the bugs and issues. Lofty hopes, but with your help maybe we can make this thing solid.

Changes
Here are the changes for this release:

  • Fixed a bug with Connection.GetSchema() that only retrieved columns when it felt like it. Now I'm using INFORMATION_SCHEMA
  • Altered the Class template to implement INotifyPropertyChanging, INotifyPropertyChanged. tysonAdded the eventing to support this as well (for anyone out there who wants to help make an UnitofWork container... I already have the basic bits in place...)
  • Added a ProviderFactory to make the instancing of IDataProvider work with an Abstract Factory as opposed to leaving it completely up to System.Data.Common. This will allow for using providers that don't implement System.Data.Common.
  • Added a Factory for creation of the QuerySurface (The DB() context, for lack of better words). This allowed me to ...
  • Added ForiegnKey properties to the Class template, so you can now access Product.Suppliers a la Linq To Sql.
  • Added Validation methods for each property on the Class template, so when you set a property you can override a "OnEmailChanged" and "OnEmailChanging(string value)" - just like in Linq To Sql.
  • Added Rodrigo Diniz's change to the _Settings template that will use your config file's connection string so you don't have to set manually.
  • Added the Inflector to the Utility class, allowing you access to methods such as Pluralize(), PluralToSingular(), ToProperCase, ToPascalCase, etc. This is a class for naming only and is part of the templates.

These aren't the only changes - Matt Warren released part 12 of his Linq tutorial which addressed 99% of the issues people were finding, including the use of variables in the Linq call. Hi IQToolkit is awesome, and is the backbone of SubSonic 3.0.

It's a complete restructuring, which will be a tremendous help as we try to fit in support for Oracle and other providers (which I'll need some help with).

I can't thank Matt enough - his posts have been a tremendous help.

You can download it here.

Setup
You go through the same process as before. To recap, you:

  1. Add a web or app.config file to your project
  2. Add a connection string to your DB
  3. Add a reference to SubSonic, which is in the folder
  4. Drop in the "Generated" folder, wherever you want it to go.

Hopefully that will be it. Everything is working pretty well for Sql Server and MySQL, but I know there's more to do. I definitely know there's some love that needs to happen WRT to Oracle, and for that I'll need some help.

The Source
I've made the source available here, in a new repository that's separate from SubSonic 2.1. I've also changed the license (on 2.1 as well) to be New BSD. Please don't read anything into this - it's just what I wanted to do.

SubSonic 3.0 Code Repo

I also want to keep the discussions out of our forums - it's too hard to manage, especially for alpha. Instead I've created a Google Group list here:

http://groups.google.com/group/subsonicproject

This is for SubSonic 3.0 Alpha ONLY. If you find bugs, I'd really appreciate you logging them here:

http://code.google.com/p/subsonicthree/issues/list

If you would like to create a patch, I'll hug you.

Using SubSonic 3.0
Just about everything is exactly the same as Preview 2, sans some silly bugs. The great thing is that if you know Linq, you know how to use SubSonic. The one major difference is that now I am using a Factory to create the DB:

 

   23         [TestMethod]

   24         public void Select_Simple_With_Variable() {

   25 

   26             Chinook.DB _db = Chinook.DB.CreateDB();

   27             int albumID = 1;

   28             var result = from a in _db.Album

   29                          where a.AlbumId == albumID

   30                          select a;

   31 

   32 

   33             Assert.IsNotNull(result.SingleOrDefault().Title);

   34         }

 

And that's about it.

If you want to take advantage of the ForeignKey stuff, you can do so like this:

 

        [TestMethod]

        public void Select_Simple_With_ForeignKeys() {

            int artistID = 1;

            var artist = (from a in _db.Artist

                         where a.ArtistId == artistID

                         select a).SingleOrDefault();

 

 

            Assert.AreEqual(2, artist.Albums.Count());

        }

 

Call for Help
If you would like to help ramp out support for your favorite database, please send me an email (using the groups list above) and your google login, and also what you'd like to do in particular.

More than anything, if you have a problem and can write a test that I can use (against the Chinook DB would be great) to verify, that would rock big time.

I'll put together some more tutorial stuff later this week.

Cheers.


Tom - December 9, 2008 - Any chance of a 2.1.1 release to make the update to the 2.1 release official before it dies? With the lack of backwards compatibility there are some of us that just wont be able to move to 3.0 on existing projects.
robconery - December 9, 2008 - Yep- I should have mentioned this



Sent from my phone. Please excuse brief replies.
applecran - December 9, 2008 - This looks great rob. I'm currently in the middle of re factoring a large application of mine, and moving it to Linq to SQL. I'm a little weary of running an alpha build in production, but wondering:



1. Will it be much of a stretch to move things from LINQ to SQL to Subsonic 3?

2. What do you think the time frame of a stable release will be?



Thanks and keep up the great work!



Yogesh - December 9, 2008 - 1. It will be some work for sure.

2. Asked the same question, didn't got a reply yet :P



@Rob:

I liked the old way where I could address parent foreign keys in SubSonic 2, so I changed class.tt to work exactly like the previous way.
SoftMind - December 9, 2008 - Hi,



Great Indeed.



Is it possible to blog or show a code demo of Subsonic 3.0 + IronRuby.



I think many Rubyists like me, would love to see it.
Filip Ekberg - December 10, 2008 - Nice release!



Just a little remark though, i would consider naming _db.Artist to _db.Artists and _db.Album to _db.Albums having them plural instead of cingular. Which makes it a little more readable and nicer :)



Otherwise, nice job!
scott - December 10, 2008 - Hi Rob - I just don't know what I'm missing. I couldn't get the earlier subsonic 3 previews to work either. I created a console app, added app.config and put in a connection string. Added a subsonic reference. I dropped the _Generated folder into my project. That's all your instructions say above. If I look at the readme, it says to change the settings.tt to change the connection string and namespace settings. I don't understand this part. Why define my connection string again? What goes in ProviderName (I am using sql server 08)? Regardless of anything I try, when I build my project, it compiles cleanly, 0 errors, 0 warnings, but I get nothing. Please help!
Johan - December 10, 2008 - And why the image title "I personally believe SubSonic is going to die a slow painful death and I don't want this project attached to a sinking rock"?



What are you trying to say?
scott - December 10, 2008 - update- I renamed the generated folded from _generated to generated. It generated classes immediately upon renaming. There are dozens of compile errors, even after adding in linq, transaction, etc references that I didn't have. I'll continue to try and get this to work.
Kevin Sheffield - December 10, 2008 - That Chris Cyvas has his head up his ass
Rodrigo - December 10, 2008 - Nice to see the Updates... thanks for mentioning my name .. a link to my blog or my project would be awsome.
swatermasysk - December 10, 2008 - This is really good. Just wanted to throw something out there.



I know you have invested a lot of time into this. However, after spending some real time with NHiberate (+Linq) and FluentNHibernate I am wondering if you might be better served if you used NHibernate to do the heavy lifting behind your templates.



The benefit would be Oracle (and many other) provider support today, less messy SQL code to manage, and giving users the option to use NHiberate where appropriate.



Thoughts?



Thanks,

Scott
Subnus - December 10, 2008 - i have made the change would you like the files ??
bbqchickenrobot - December 10, 2008 - Love the "Iron" Mike Tyson pic! lol XD
bbqchickenrobot - December 10, 2008 - What is the point of using NHibernate behind this? It's big bulky and ugly and tied to XML. Also, you're just adding a layer of complexity. Lastly, I believe Rob stated he wanted to have a more open system as people "always seem to find the edges" - I vote a huge NO on this idea.



If I want to use NHIbernate, why don't I just use NHibernate!?!?
swatermasysk - December 10, 2008 - 1. With code generation, who cares about XML.

2. Please re-read, with FluentNHibernate there are no XML files.

3. In regards to edge cases, why not have something which can easily handle the edge cases.



Again, I am not saying you would ever have to muck around with NHibernate directly. You can still use the nice layer generated today, I am just saying instead of re-inventing the wheel in regards to query building and data access, why not use something that already works (and will give Oracle, MySQL, and many others support today).



-Scott
Robert G - December 10, 2008 - Rob,



Several things.



1. The stored proc wrappers don't compile. Consider the following generated line:



StoredProcedure sb=new StoredProcedure("ms_rpt_Scheduled_Revenue_Summary",new DbDataProvider("MyDatabase"));



DbDataProvider class does not have a constructor that takes a parameter. I am not sure how this is supposed to play out.



2. I'd add to the readme.txt that the project should add dependencies to System.Transactions and System.Data.Linq

Makes for a smoother experience.



And I sent you a patch for the tinyint issue.
robconery - December 10, 2008 - Ugh - that's what I get for switching to a test db without SPs. Thanks.
rgraner - December 10, 2008 - Rob, love what you do and love both starter kits (2.0.3 & MVC), do you think that you'll be updating either of them down the road if so, both or just MVC?
Cosmin Onea - December 10, 2008 - I watched today some webcasts about Subsonic and I am really impressed.



I just downloaded this version and I think there could be some problems with serialization with regards to events exposed by the objects.

Have a look here:

http://www.cosminonea.net/2008/12/10/Subsonic30AndAPossibleSerializationProblem.aspx
robconery - December 10, 2008 - Good post - keep in mind the templates are there for you to fix as needed as

well, if serialization is an issue. That said - I'm hoping to start a

template share (somehow) and would love your ideas.
justin - December 10, 2008 - Hey Rob,



I don't know if this is what you're looking for but there's a new project called NCommon that has a well thought out unit of work pattern from www.codeinsanity.com. Direct link to the project: http://www.codeplex.com/ncommon
Keney - December 27, 2008 - tks.......It is very great!
rutgersmit - January 7, 2009 - I had to modify line 76 of QuerySurface.tt, added the CleanUp.

I did that because of getting rid of table prefixes.

Is it a bug or am I missing the point?

Cezar - January 13, 2009 - Hi!

I like SubSonic a lot!

So... Is the SubSonic 3 Alpha compatible with Oracle?



I'm try to generate for Oracle..






connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Oracle92)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=Oracle92)));User Id=TRACTEBEL_SITE;Password=TRACTEBEL_SITE"/>












connectionStringName="SRSCnt" generatedNamespace="SRS.DataAccess" />







Thanks!!!
Gecko