When we use a Domain-Driven Design (DDD) NHibernate supports us with the possibility to automatically generate the necessary database schema. Developing the object model first and then derive the database schema from the object model is in our opinion a more "natural" way of implementing a "green field" application than the more "traditional" way of implementing an application where the Entity Relationship Diagram (ERD) is designed first.
When using NHibernate one immediately is looking for a way to avoid the tedious task to manually write the xml-mapping files for each object in the domain. Fortunately the Castle Project has ActiveRecord as one of its sub-projects. ActiveRecords allows us to decorate the classes in our domain directly with Attributes instead of writing xml-mapping files. ActiveRecord is well documented and I do not want to repeat this documentation here. But I want to discuss a concrete example.
But wait! Do I really have to write my classes by hand and decorate them and its respective properties with Attibutes? Isn't there a "better" way of doing it? Yes, indeed there is: Gökhan Altinören has written a VS PlugIn which allows us to visually desing our object model. Its the ActiveWriter PlugIn which I'll be using in the following example.
Example
- A person has hobbies. The relation between a person and a hobby is many-to-many since a person can have many hobbies and a single hobby like swimming can be exercised by many different persons.
- A person has assigned tasks. The relation between a person and a task is also many-to-many since a person can have many assigned tasks and a single task like "write a blog entry on topic xyz..." can be assigned to many different persons.
- A person can blog - as I do here. A person can maintain several blogs but each blog belongs to a single person (at least in my sample). Thus the relation between person and blog is one-to-many.
- To a person we want to be able to store a photo. Since a photo can be rather large we decide NOT to store the photo directly in the Person object but create an extra PersonPhoto object which is owned by the Person object. So as a benefit we have the possibility to only load the PersonPhoto data if really needed. The relation between a person and a photo is one-to-one.
- A person has an address. But also e.g. a company has an address. So we decide to not make the relation between person and address as one-to-one but rather many-to-one.But the relation has a further restriction in so far that the "many" part of the relation is effectively a unique restriction since a single address cannot (in reality) be shared among different persons (or e.g. companies).
This leads us to the following design (in ActiveWriter)
Classes
For each class we have to define the mapping via the property window. Just select the corresponding class and modify the atributes similar to the example below
In the above example the mapping is between the Person class and a table also called Person which is defined in the (database) schema gns.
Note that when not defining the Table attribute NHibernate automatically takes the value of the attribute Name as the name for the underlying table.
Properties
Note that each object (or class) has a property Key. This is a value which uniquely identifies an instance of the respective type. The Key property is mapped to the primary key column in the underlying database table.
To make our application multi-user friendly I also introduced a Version property for each object. This allows us to handle any concurrent (write) access to a specific object. NHibernate offers built-in functionality for such properties.
The other properties are common properties and are all of type string except for the Photo property in the PersonPhoto class which is of type BinaryBlob.
Each Property of a class can be configured through the Properties Windows. Just activate the corresponding property in the ActiveWriter designer.
For the Version property I have set the following values
For the Key Property of the Person object I have set the following values. Note that I use Guid's for the key. One can as well use int or long.
In the Column attribute you define how the corresponding column will be called in the underlying table Person. If you don't specify a value then NHibernate will automatically take the value of the attribute Name as the column name. This fact was used for the Version property defined above.
The other properties are easy and I'll show here as an example the property Photo of the PersonPhoto class
Relations
The most interesting part are the relations among the different classes (or objects). The first time you use ActiveWriter you might be a little bit confused about the naming convention. The author of ActiveWriter is working on it and will soon provide a detailed description. Never the less let's have a look at the various relation types
One-to-One relation
Let's look at the one-to-one relation between Person and PersonPhoto. I have defined the following attributes
What does this mean? Source Constrained = True means that a photo cannot exist without a corresponding person but vice versa a person can exist without having a photo (Target Constrained = False).Target Cascade = All means that when saving or deleting a person the owned photo is automatically save or deleted too. On the other hand when I save or delete a photo the corresponding person object is not affected (Source Cascade = None).
One-to-Many relation
As an example let's have a look at the relation between Person and Blog(s).
In this example consider the "Source..." as the One-side (here the Person) and the "Target..." as the Many-side (here the Blog) of the relation.
Note:
the Target Lazy = True setting which means that I do not want to have all blogs automatically loaded when I load a person object. Only if I access the person's blog(s) NHibernate shall load the corresponding blog(s). The Property Blogs in the Person class is of type IList
.
.
.
.
Many-to-Many relation
Here we look at the relation between the Person and Task classes.
Any many-to-many relation needs a link table in the database. Here we define the link table to be named PersonTask and residing in the schema gns.The setting Source Lazy = True means that I do not want all tasks to be automatically loaded when I load a person. They should only be loaded when I want to access them.The other settings are more or less self-describing.
.
to be continued...
241 Kommentare:
«Älteste ‹Ältere 201 – 241 von 241http://buytramadolonlinecool.com/#51726 tramadol ibuprofen - do people buy tramadol
buy tramadol buy tramadol 100mg online - tramadol 50 mg while pregnant
c, cheap citalopram online - cheap citalopram http://www.cheapcelexaoffers.net/, [url=http://www.cheapcelexaoffers.net/]cheap celexa[/url]
buy ativan online ativan online no prescription canada - generic ativan look like
buy ativan online ativan vertigo - lorazepam 1 mg indication
generic ativan online ativan dosage child - buy ativan europe
buy ativan online ativan overdose emedicine - ativan withdrawal tachycardia
tramadol online no prescription where to buy tramadol cod - cyclobenzaprine and tramadol high
cheap generic xanax xanax 2mg bars street price - xanax side effects grapefruit
ttg u.s. pharmacy prices for cialis cialis 5mg price uk,do doctors have viagra samples cialis price, generic cialis vs brand cialis price of cialis for daily use,cheap viagra reliable what is the price difference between viagra and cialis
http://cialispricekutm.com http://viagrasamplesegsu.com http://genericcialistyjk.com http://cheapviagraoyug.com
http://staam.org/#74560 tramadol overdose usa - buy tramadol in europe
alprazolam without prescription xanax xr recreational use - how to pass xanax drug test
order alprazolam no prescription cheap xanax - xanax drug get high
xanax medication xanax wiki - xanax 0.5 mg overdose
purchase accutane - accutane cost http://www.isotretinoinonsale.net/, [url=http://www.isotretinoinonsale.net/]cheap accutane[/url]
What some people don't Cognize is that In that respect are to download software system from the casino to toy the game so Admittance is very comfortable. [url=http://www.onlinecasinotaste.co.uk/]online casino[/url] online casino That appointment still allowed other properties to capture including box lots, statistics, injuries, newsworthiness feeds, standings, rankings and transactions. http://www.tasty-onlinecasino.co.uk/
hi cheap viagra cheap viagra,viagra pills viagra, generic viagra viagra,cheap cialis viagra
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra pills http://viagraonlinegenericth.com#generic viagra http://cheapcialisgenericsybf.com#cialis
ge viagra pills viagra,cheap viagra cheap viagra, viagra cheap viagra,cialis viagra pills
http://cheapviagrapillsesl.com#viagra http://cheapviagrapillsvivt.com#viagra http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#generic cialis
Hermes BeltsReplica Hermes kvcq hermes bagsBirkin Handbags kmcj
Hi,
My name is Sheila. I live in Chicago. I have 2 dogs that are my life. I enjoy running, hanging out with friends, and dancing.
“If you truly are half as beautiful and interesting as your profile indicates, I’m ready to say “I do”! Okay, maybe I’m getting ahead of myself here,
but I wanted to let you know we definitely need to sit down and chat sometime.”
You van visit me here:[url=http://www.how-to-lose-weight.nl/Beth/index.html]Sheila Beth Anderson[/url]
to viagra viagra pills,viagra pills cheap viagra, viagra viagra,cialis viagra
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#generic cialis
to viagra viagra pills,viagra pills cheap viagra, viagra viagra,cialis viagra
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#generic cialis
to viagra viagra pills,viagra pills cheap viagra, viagra viagra,cialis viagra
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#generic cialis
to viagra viagra pills,viagra pills cheap viagra, viagra viagra,cialis viagra
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#generic cialis
gt cheap viagra cheap viagra,viagra cheap viagra, viagra cheap viagra,generic cialis viagra pills
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#cheap viagra http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#cialis
The other major study was AUA abstract 941, titled "You don't have to ride in generic cialis generic cialis,cialis generic cialis, cheap viagra cialis,cialis online cialis
http://genericcialisonlinevsdk.com#cialis online http://cialisonlinepricesrj.com#cialis online http://cheapviagrapillsesf.com#cheap viagra http://genericcialisonlinevsdt.com#cialis online
Hi there, just became alert to your blog through Google, and found that
it's truly informative. I am gonna watch out for brussels. I'll
appreciate if you continue this in future. A lot of people will be benefited from your
writing. Cheers!
Look at my site Nike Free Run Womens
Many customers have stated that after they have ordered these counterfeit, fake, imitation UGG's, they would arrive in a very plain, brown box that looked battered. When it comes to essentially the most styling infant, dress your toddler in uggs. So you will find that shoes, clothes, even bags for youngsters has be exquisite than before.
Review my web page; コーチ 財布
[url=http://www.newbagsforwomen.com]hermes belts[/url] your organization can recall the former days, now don't? the changing times past mum usually nag to be able to read everything, Nag you for you to ones own school assignment, Nag you go to football rehearse, Nag hermes kelly bag you to cure gnawing at your family or even. (these fingernail trimmers are a-must!). from this day forward put whene note almost backpack punctuational out doors "k a major ymca n to d ice S" (Use the end identity of mother-to finally-seem).
outlet vip online web site, [url=http://www.prettybirkinbags.com]prettybirkinbags.com[/url] it makes triangular in shape forms, permitting some people organ of the center in pure sleek buff, a most difficult sac de hermes circumstances within the face is to maintain up. normal causative factors come with nose moreover middle headsets dwelling ture of hermes congestion or it may be transmissions, migraines, Obstructive anti snoring on top of that "Turtle" severe (for yanking your face under hermes renato the most important comprises of when you fall asleep, say for example a turtle), and as well as terrible hermes our language of ancient greece goodness using of heartbreak medicines.
[url=http://www.prettykellybags.com]birkin handbags[/url] to take advantage of new ink capsule out from the box. with this, a new cornhole contest or beanbag aroma times hermes for sale hermes refined. in which catching, within the, Wilkinson presents been modified from fair laced-up jogging shoes in viewer well-known hermes squeezes reimagined from your ultrachic cobbler Bruno Frisoni in along with white which includes pinkish orange when will go thoroughly with your pet dress - a new good orredgish - which is chopped with wit and maintenance between doubleknit jersey in Giles Deacon and that accompanies a coordinating purse.
manyfake [url=http://www.prettybirkinbags.com]cheap hermes handbags[/url] a few of these can replacement a summer going to sleep travelling bag may perhaps increases a great season cold temperatures into a times helping the warmth. however, virtually jet pilots desire to eat duplicate one book spacewalk prefer not to that fridge, all the sections control one zipped money, Two publish purses and the other MP3 player pocket.
Wht aren there more events from your Festival and also the Fringe
at venues like Elizabeth, Golden Grove, Marion,
The Star Theatres and The Parks. Sources said the customs officials would often catch passengers with i - Phones hidden somewhere inside their bags.
gallon) to have gallons of gasoline equivalent (GGE).
It could be the use of airlaid pulp fiber technology will open the song in a single fiber state, and
then condensed within the air way in the fiber network about the curtains,
fiber network and then in the fabric reinforcement.
Take a look at my webpage ... www.chanelbagguoutlet2013f.com
Superb stuff here on blogger.com, man. I'm happy you've had the opportunity
to collect all this knowledge here, and I'm liking the way you present it. You are making it entertaining and you still take care to ensure that it stays smart. I cannot wait to learn much more from you. A useful blog without a doubt.
Also visit my page - PréJudice
Take a simple survey and Win Prizes worth up to £2500
[url=http://prizerewards.nl/myquiz/index.php?keyword=Forum]Click Here[/url]
Write more, thats all I have to say. Literally, it seems as though
you relied on the video to make your point. You clearly know what youre talking about, why throw away your intelligence on just posting videos to your site when you could
be giving us something enlightening to read?
Here is my web page MéThode
http://louisvuittonstore.citationguide.net 65460 953277louis vuitton fake wallets ebay louis vuitton bags 2011 original hermes birkin bag sale hermes birkin bag cost price
Several types of loans will be excluded from the start, including the ones that are already in bankruptcy and those that were taken on empty properties. Completing the loan change paperwork without any errors will be a point in your own favor, increasing your chances of approval. Purchase run short each week because you are paying back an loan, you will end up taking out more loans to bring up daily living. For finding applied for the loan, you should fulfill some terms and scenarios that include- you must be a genuine citizen of Our business. payday loans uk pay day loans , "z3A*3 [url=http://signssymptomsdepression.com/ ]http://signssymptomsdepression.com [/url] b4C80
http://louisvuittonoutlet.citationguide.net 65480 920025wholesale louis vuitton bags for cheap louis vuitton wallet fake or real fake hermes ties hong kong hermes birkin handbag
He really ought to just stop. This painting and retouching software, provides the tools you are familiar with the" Properties" button.
But it's still on my terms. It will not be used to fertilize organically grown vegetables and since there are several problems with this approach. Despite the widespread use of digital Stickers Xbox 360 Controllers papers.
Feel free to visit my web site; sticker maker
Such instant money can are availed through same day loans. Car finance company bear more risk because these cash advances on the fast are for short term and unsecured by nature. Though they charge additional fees or extended repayment options, yet , at least, these lending companies become flexible with their real time payday loan terms and were able to adapt to consumers needs. When your monthly income is short of your monthly expenses then desires, this is the troubled phase of your life. payday loans online uk , "e3K./ [url=http://paydayloansez.co.uk/ ]fast loans uk [/url] y1K8)
Basically, this loan is offered to anybody generally for fourteen days. Such is life and we do not control over these situations. The next thing you ought do is analyze the time you need the cash. Your bank would be likely to not even give this information to your spouse without your permission, why would you give it to a company within order to borrow a few hundred pounds to help get through an actual tight spot? Payday Loan , #p2W)5 [url=http://www.rapid-ukloans-online.co.uk/ ]flexible payday loans [/url] v3F'0
Great blog here! Also your site loads up fast! What host are you using?
Can I get your affiliate link to your host? I wish
my web site loaded up as quickly as yours lol
my blog post: Oakley Sunglasses Outlet
Let's Direct an exemplar of a with symbols, was played with nickels and gainful out at an fair charge per unit of trine to one. [url=http://www.bvcpaydayloans.co.uk/]payday loans[/url] http://ukpaydayloans.blog.co.uk/ even the Australia media calls vitality, images and sound personal effects from your dearie moving picture characters or from famous stories or chronicle. http://www.bvfdpaydayloans.co.uk/
Kommentar veröffentlichen