Note that from the Summer of NHibernate screencasts, if all you are interested in is discovering effective methods to generate your classes + mappings from an existing schema, then you should really focus in on "Session 08: Techniques for Effective Database-Driven Modeling" as it demonstrates from start to finish how to use MyGeneration to reverse-engineer your classes + hbm files from an existing schema.
The tweaked MyGeneration template used in the screencast (which is *not* the same as many you will find online in the MyGeneration template library) is in the root of the \DataTransfer\ folder in the code sample available for download with that installment of the series from the same site mentioned in Chris' post. Note that the template was designed to function against NH 1.2 and will need (some minor) tweaking to generate classes fully-compatible with NH2.x and later (most notably the *entire* public surface area of the classes needs to declared virtual now instead of just the properties as the present template available in the does) but these template changes are minor and you should be able to affect them with little effort. It sounds like you have some practical experience in using ORM approaches in actual projects, so much of what's in this post is probably old-hat for you, but you might want to consider my thoughts on the merits of code-generated classes and mapping files as I outlined some time ago in this blog post: http://unhandled-exceptions.com/blog/index.php/2008/10/04/the-four-stages-of-object-relational-mapping-a-progression/ Essentially, if you DB so completely drives your object model + mappings that you can code-gen them from the schema, then you're really not leveraging OR*M* to its fullest extent and so might be better off with a more ActiveRecord-style approach to data access (Castle's impl. or otherwise) for your application than 'full', naked NHibernate since in this case your 'objects' are really just glorified DTOs. You (of course) know the context for your project better than anyone else, so only you can make the right decision about the relative merits of one approach v another for your specific use-case. Hope this helps. -Steve B. On Jan 8, 12:45 pm, Chris Nicola <[email protected]> wrote: > I would try using another template or build your own that is customized to > the output you want. I can't remember which template I used, but it wasn't > one of the "doodads" templates, you need to download the nHibernate > templates for MyGeneration as I don't believe they are included by default. > > I should also point out there is quite a bit of documentation (often in the > form of blog posts etc.) on using nHibernate with ASP.NET you should check > out nhforge.org as one source. You should also consider watching the "Summer > of nHibernate" tutorialshttp://www.summerofnhibernate.com/. These explain > almost all of the basic concepts that are useful to know when using > nHibernate. > > One thing you might check out (I haven't used it myself yet) is Visual > nHibernate which is a commercial software product that gives you a visual > designer. I believe you can drag and drop from the database to create > entities from tables. Not sure how good it is though.http://www.slyce.com/ > > Chris > > On Fri, Jan 8, 2010 at 9:26 AM, boban984 <[email protected]>wrote: > > > Thank u guys > > > I used MyGenration to genrate dOOdads -> busines entities for all my > > tables. > > > The thing is i ended up with 70 C# classes (for the 70 tables) , all > > the classes have more than 1500 rows . > > Where as in JAVA the eclipse plugin for hibernate Generated about 200 > > lines of code , that include only the columns of the tabels as private > > variables and the getters and setters. > > Something like this: > > @Entity > > @Table(name = "staff", schema = "public") > > public class Staff { > > > private long staffId; > > private Institution institution; > > private Person person; > > private Date fromDate; > > private Date toDate; > > private RoleType roleType; > > > public Staff() { > > } > > > public Staff(long staffId, Institution institution, Person person, > > Date fromDate, Date toDate) { > > this.staffId = staffId; > > this.institution = institution; > > this.person = person; > > this.fromDate = fromDate; > > this.toDate = toDate; > > } > > > �...@id > > �...@generatedvalue(strategy = GenerationType.IDENTITY) > > �...@column(name = "staff_id", unique = true, nullable = false) > > public long getStaffId() { > > return this.staffId; > > } > > > public void setStaffId(long staffId) { > > this.staffId = staffId; > > } > > > �...@manytoone(fetch = FetchType.LAZY) > > �...@joincolumn(name = "institution_id", nullable = false) > > public Institution getInstitution() { > > return this.institution; > > } > > > public void setInstitution(Institution institution) { > > this.institution = institution; > > } > > > �...@manytoone(fetch = FetchType.LAZY) > > �...@joincolumn(name = "person_id", nullable = false) > > public Person getPerson() { > > return this.person; > > } > > > public void setPerson(Person person) { > > this.person = person; > > } > > > �...@manytoone(fetch = FetchType.LAZY) > > �...@joincolumn(name = "role_type_id", nullable = false) > > public RoleType getRoleType() { > > return this.roleType; > > } > > > public void setRoleType(RoleType roleType) { > > this.roleType = roleType; > > } > > > �...@column(name = "from_date") > > public Date getFromDate() { > > return this.fromDate; > > } > > > public void setFromDate(Date fromDate) { > > this.fromDate = fromDate; > > } > > > �...@column(name = "to_date") > > public Date getToDate() { > > return this.toDate; > > } > > > public void setToDate(Date toDate) { > > this.toDate = toDate; > > } > > > public String toString() { > > return person + " " + institution; > > } > > } > > > Then i would make the DAOs for the entities , and Management classes > > using SPRING. > > The DAOs would have all the code for manipulating data. > > > Now with NHibernate and MyGeneration , i have all the entities again > > with all the variables from the tables columns , but also some EXTRA > > code :) . > > The next step would be to make the mappings. > > > I thought the process would be similar with JAVA\Hibernate. > > I would appreciate if anyone could give a link to a tutorial or > > recommend a good book , describing how to make a simple app using > > ASP .net , NHibernate. > > All the tutorials i found were not describing code generation and the > > DB was not made. > > > Im looking for a tutorial that would describe the process of making an > > app starting with a Finished DB schema , then generate the Classes for > > the tables , generate the mapping , making DAOs if thats the way to do > > it in asp.net C#. > > > Thank u all again > > i know these are noob questions , but the Documentation and tutorials > > on using NHibernate with ASP.net are really scarce. > > > -- > > You received this message because you are subscribed to the Google Groups > > "nhusers" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<nhusers%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/nhusers?hl=en.
-- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
