开发者

Work with relations in Subsonic

I am using subsonic 3.0.3(ActiveRecords) in my winforms project. I am trying very hard 开发者_如何转开发to use Collections for my entities but so far I have been unable to do that .

Please allow me to make myself more clear.

While going across many tutorials, I have seen, that Subsonic will generate two classes. One is a collection class and the other the entity object. say for example, if i have a person table in my database, subsonic will generate a Person Entity class and a PersonCollection class. A website(sorry, i forgot, which one) also mentioned that I need to use a tool called SubsonicCommands to perform this kind of operatin with subsonic. I downloaded a version of the same for Visual Studio 2008 from this website http://oldtownit.com/media/files/SubSonicToolsSetup.zip

I can run the tool and generate the classes, but the project wont compile , because it is looking for this class SubSonic.Utilities. Pray, tell me where can I find this class? I tried looking for this class, in the ~\Program Files\Subsonic\SubSonicTools\source\ but could not find it.

Also, I checked the code,The collection class was still not being generated. In the above case that I tried, there were two classes generated, Person Entity Class and the PersonController Class

My AIM :

What I am trying to do with subonic is the how LLBLGEN works.

LLBLGEN Example

say for example, if there are two tables, Items and Suppliers and their is an intermediate table called ItemSuppliers which has a many to one relation with both the tables (Items and Suppliers), then in LLBLGEN ,I can do something like

Item item = new Item(ItemFields.ItemId==1); item.ItemSuppliers.DeleteMulti()

which would delete all the records related to an item whose ItemId is 1 in the ItemSuppliers table. This can also be done with respect to the Suppliers table (of course making the proper changes)

Also I would like to know, If i can return all the ItemSuppliers for a particular item (from the example above) if i returned the parent object .

again an example from LLBLGEN Item item = new Item(ItemFields.ItemId ==1); MessageBox.Show(item.ItemSuppliers.Count.ToString());

The above message box would dispaly 2 if there were 2 suppliers for an Item (from the itemSuppliers table)

Epilogue:

Subsonic is an awesome tool to work with. I have used it often , in some ultra small projects, but I would like to use it with a little bit more complicated project,this time which has some relations between tables.

Also, if somebody could suggest , if I can do , what I want to do with subsonic , that would be awesome and sweet.


You start by saying you're using version 3.0.2 but it seems you're using Subsonic 2.2 and 3 - You should use one or the other.

The utlities class in version 2. Downloadable from: http://github.com/subsonic/SubSonic-2.0/blob/master/SubSonic/Utility.cs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜