views:

285

answers:

1

I'm started looking at Subsonic just yesterday and having trouble figuring out how to do even the most basic tasks. I've watched the demos for ActiveRecord and SimpleRepository, but they don't fit what we want so I'm trying to use the Linq Templates.

The getting started guide for Linq walks through enough to do a query, but how do I do other things like insert a record and get it's auto-increment ID back?

Is there a reasonably comprehensive guide to using Subsonic Linq somewhere?

+1  A: 

Well there is this: http://subsonicproject.com/docs/Using_AdvancedTemplates

Which I can see is a bit sparse :). It works just like Linq to SQL in most cases in that you need to create "DB". That DB allows you to Insert, Delete, etc for all the objects. You can also do aggregates and so on.

using(var db=new NorthwindDB()){ db.Insert.Into("Name").Values("New Name").Execute(); }

The tools used to interact with the DB follow along with our Simple Query tool: http://subsonicproject.com/docs/Simple_Query_Tool

If you want more things done for you (like getting the new id back, etc) you should stick with ActiveRecord.

Out of curiosity - what doesn't fit?

Rob Conery
Hi Rob, thanks for the fast reply. A couple of reasons we veered away from ActiveRecord - 1. we probably didn't understand it correctly, 2. running simple unit tests against it crashed MySQL data provider on shutdown (Null Reference), which didn't seem to happen with Linq Templates, 3. The Linq stuff just seemed to agree with my thinking more.Conceptually I really like sub-sonic especially after looking at hibernate for a few days, but currently I'm pretty confused. Do I use ActiveRecord, or Linq. Where's some good examples or documentation etc...I'll go try ActiveRecord again.
cantabilesoftware
Hi Rob, I took another look at ActiveRecord again re the crash: This works: var db = new testDB(); db.Insert.Into<company>(c => c.name) .Values("Acme") .Execute();But this crashes (not immediately, on shutdown, using MySql) company c = new company(); c.name = "Acme"; c.Save();Let me know if you want more info...
cantabilesoftware
i use subsonic with mysql and to get around problems i end all table names with an s and all primaryKeys are TableNameID ie table baskets with BasketID as primaryKey all in activerecord also for insert var testinsert = new TestTable{TestName = "test",TestOther="test 2"}; testinsert.Add(); thats the easiest way to insert i find as the other method wont convert DataTime to mysql DateTime and crashes on mysql but if you use the model then subsonic converts correctly
minus4
The crash I talk about above can be fixed by building from the latest source. At this point in time, using the download from the sub-sonic site crashes in the case described.
cantabilesoftware