Subsonic table mappings - subsonic

I've searched a lot and I haven't really found an answer.
Is it possible to use POCOs with Subsonic?
How do I map tables (which do not look like the POCOs) to my classes?

SubSonic doesn't provide a built in way to map tables to your POCOs.
The closest it would come would be using the ActiveRecord portion of SubSonic which would generate one class per table (with properties for each table column and foreign key relationship to other tables).
Depending on how your POCOs look, you might be able to get data easily (or not) between the generated ActiveRecord classes and your POCOs. Also, the generated ActiveRecord classes are created via templates which you can modify to fit your needs.

Related

how to generate classes and properties using Entity bean class name and property names?

I'm successfully generating jOOQ classes using the jooq-codegen-maven plugin together with the jooq meta hibernate extension.
The names of the generated classes and methods for tables/column are using the actual DB table and column names.
Is possible for the generation to use on the #Entity class simple-name and the #Column instance variables names instead the #Entity(name=TABLE) and #Column(name=COLUMN) ?
To me it will be more intuitive to have the same names as the JPA classes when using jOOQ to create queries.
Thanks
jOOQ doesn't really "know" your entities. Behind the scenes of the JPADatabase, there's a simulation of installing the generated SQL for your entities in an actual database (currently, as of jOOQ 3.15, in H2, but that might change in the future). From then on, jOOQ will continue to connect to an actual database to reverse engineer things, not knowing that this simulated database originates from JPA entities.
As such, it is not possible to "remember" what alternative names you gave to those tables and columns.
However, you might know, and have some naming conventions, which you can encode in a generator strategy.

How to keep data in Object

I have a table or tables in sqlServer. I want to take data from database and keep this table's data into objects like class, but I dont want to keep this data into dataset.
What are those ways to keep data into objects taking data from database?
How can I pass data into object but not in dataset or datatable?
ORM is what you should be looking for.
For .Net framework you can look into
Entity Framework
LINQ to SQL
NHibernate
Dapper
ORM is the solution as mentioned above.....
Better use entity frame work that is good for this purpose.......it will creates entity classes with all your tables in the database.
In short: as it is suggested in the comment, some type of ORM (Object relational mapping) will do that magic for you.
Good references on this topic are the followings:
4 Benefits of Object-Relational Mapping (ORM)
ORM mapping data to objects
DataObjects.Net - ORM Framework for RAD - Introduction
Edit: To choose the right ORM for your problem, look at this Wikipedia article
List of object-relational mapping software.

Complex Type in Subsonic 3

I am going to use subsonic 3 in a large enterprise winform application.
what i saw in my personal tests is that subsonic cannot handle complex type references well.
for example if we have an ADDRESS complex type in PERSON object , as far as i saw subsonic just created the PERSON table and is not caring about the Address property of it !
i was wondering how can i solve it ?
Secondly, we have inheritance in our objects, how subsonic can handle it with table-per-subclass strategy?
SubSonic isn't well suited to these scenarios. Regarding complex types you could write a service/repository to handle saving and building these types, but there's no pre-existing way of mapping this to the database.
The same goes for inheritance schemes.
You might want to look at more full-featured O/RM like NHibernate or EF.

Subsonic Simple Repository String Lengths

I'm playing around with the SimpleRepository provider (with automigrations) in SubSonic 3 and I have an annoying problem:
The only way I can control the string length in my database tables is by adding the SubSonicStringLength or SubSonicLongString attributes to the properties of the objects that need to be persisted.
I don't really want a dependency on SubSonic anywhere except in my repository class, and certainly not in my model objects if I can avoid it.
Are there anyways to get round this or am I stuck using SubSonicStringLength and the other attributes?
Basically the only way around this would be to have a DTO object that you map to/from your SimpleRepository classes inside your repository. You could use a mapping tool like AutoMapper to convert to/from your DTOs to your SimpleRepo objects.
This would isolate your application from SubSonic dependencies outside of your repo but would obviously involve a non trivial amount of work.

Subsonic: Bring me to tiers

This is an embarrassingly basic n-tier question.
I've created a DAL project in VS2008 with subsonic. It's got a widget class, a widgetcollection class, and a widgetcontroller class.
I've created my Business logic project (no I can't put it in the same tier) that references it. Using certain business criteria, it selects a collection of widgets in a function that returns a widgetcollection.
My question is: how does my GUI layer bind the collection to a grid? I know that the widgetcollection is a valid datasource for a datagrid, but how does the GUI layer know what a widget and widgetcollection are? Surely I don't have to reference the DAL from the GUI, that negates the whole point.
Firstly, I dont think this is an embarrasingly basic n-tier question.
It is a very interesting subject and one I attempted to stimulate discussion for in the old Subsonic Forums.
I share your reluctance to expose my GUI layer to the DAL.
My GUI layer only talks to BLL using the vocabulary and topics of my own Entity Model and only returns my own entities or lists or in some cases Data Tables.
My BLL only talks to a MAPping layer which maps Fetches,Saves etc to the appropriate DAL CRUD methods and converts the returned Subsonic types to my Entity types.
In doing this I was suprised at how much of Subsonic I had to duplicate and at times I felt I was going down the wrong road, I am feeling more comfortable with it now, though it still needs refactoring and refining.
For example, finding a flexible, generic means of indicating to my BLL which row(s) I wanted returned in a fetch was a challenge I hadn't expected and I finished up writing a generic queryClass with fluent interface which looks a lot like a Subsonic Select.
FWIW, I think you are headed down the right track, I guess what you have to do though is decide how you want to define those Subsonic types to your GUI.
Rob has an interesting discussion you may be interested in.
(using SubSonic 2.x) In my BLL classes I have a property which gives an object reference to the relevant DAL class. My UI form has a reference to the BLL class, so from the form I can address the DAL properties and methods via .BLL.DAL.xxxx
FWIW, I have never managed to successfully bind a SubSonic collection to a DataGridView. As alternatives, I sometimes use the collections .ToTable() method to create a DataTable and then bind to that, or alternatively I manually bind using .AddRow()
Look at the documentation for IBindingList Interface in MSDN, it has a pretty good sample.
Create, for example, a CustomersList class in your model that uses a Customer class in your BLL. Bind the grid to an instance of the CustomersList class. The presentation layer has no knowledge of the subsonic table classes.
You probably need to use an Interface. You can easily create an interface based off of the Widget in your Dal(right click on the class and create an Interface from the class). Next take the Interface and add it to your Business Logic Layer or a seperate project just for interfaces. Once you have done that you can add a reference to the Interface both in the DAL and in the GUI. This can also help if you ever change your data storage from a Database to XML etc. etc.

Resources