Jeffrey, I am puzzled how the model should be able to work, In completeOrders table we have a status field that could be Status.Incomplete, when is a record added to Incomplete orders table then ?
Please advise on existing functionality. Kind regards, On 24 jul, 15:48, Jeffrey <[email protected]> wrote: > Hi, > > Thank you for your reply. However I do not think discriminator is the > way to go. As you can see from my code sample that I don't have a > discriminator column in any of the tables. My issue is that I need to > be able to map CompleteOrders table and InCompleteOrders table to a > single object (preferably an Order class) and I could do this using > 2nd or 4th example from this > linke:http://ayende.com/Blog/archive/2009/04/10/nhibernate-mapping-ndash-in.... > However in the Order class I also need to map a collection of > OrderItems and I have no idea how to do this as OrdersItems are > separated into 2 separate tables (InCompleteOrderItems table and > CompleteOrderItems table). > > Kind regards, > > On Jul 24, 10:16 pm, Nexus <[email protected]> wrote: > > > > > Hi, > > > You should be using a discriminator in your mapping > > seehttp://www.nhforge.org/doc/nh/en/index.html#inheritance > > > Kind regards > > > On 24 jul, 09:22, Jeffrey <[email protected]> wrote: > > > > I am working against an existing database. The databse itself is > > > poorly designed. I am trying to use NHibernate to map my domain models > > > in C# to the database. > > > > The database structure is as below: > > > > Customers table > > > CustomerId INT PK > > > Property1 varchar(255) NOT NULL > > > > InCompleOrders table > > > InCompleOrderId INT PK > > > CustomerId INT FK > > > Property1 varchar(255) NULL > > > > CompleteOrders table > > > CompleteOrderId INT PK > > > CustomerId INT FK > > > Status INT NOT NULL > > > DeliveredOn datetime NOT NULL > > > PaidOn datetime NOT NULL > > > Property1 varchar(255) NOT NULL > > > > And then I have tables like: > > > > InCompleOrderItems table > > > InCompleOrderItemId INT PK > > > InCompleOrderId INT FK > > > Property1 varchar(255) NOT NULL > > > > CompleteOrderItems table > > > CompleteOrderItemId INT PK > > > CompleteOrderId INT FK > > > Property1 varchar(255) NOT NULL > > > > My C# domain models are as below: > > > > public enum Status > > > { > > > InComplete = 1, > > > Pending = 2, > > > Complete = 3} > > > > public abstract class BaseOrder : Entity > > > { > > > public string Property1 {get;set;} > > > public Status Status {get;set;} > > > public string Reference {get;set;} //this is unique per each order > > > public ISet<BaseItem> Items {get;set}} > > > > public class InCompleteOrder : BaseOrder > > > { > > > //select from InCompleOrders table > > > public override Status Status > > > { > > > get { return Status.InComplete; } > > > }} > > > > public class CompleteOrder : BaseOrder > > > { > > > //select from CompleteOrders table > > > public DateTime DeliveredOn {get;set;} > > > public DateTime PaidOn {get;set;}} > > > > public abstract class BaseItem : Entity > > > { > > > public BaseOrder Order {get;set;}} > > > > public class InCompleteItem : BaseItem > > > { > > > //select from InCompleOrderItems table} > > > > public class CompleteItem : BaseItem > > > { > > > //select from CompleteOrderItems table > > > > } > > > > I want to unify Order and Item, however due to the existing databse > > > structure I am really struggling mapping it. > > > > I want to be able to do things like: > > > public Order GetByReference (string reference) > > > { > > > var repoOrder = new Repository<Order>(); > > > var bo = repoOrder.FindOne(query); > > > //query = Restrictions.Eq("Reference", reference) //reference = > > > "abc" > > > //and this will generate a SQL similar to: > > > // > > > //SELECT CompleteOrderId > > > // , Status > > > //FROM CompleteOrders > > > //WHERE Reference = 'abc' > > > // > > > //UNION > > > // > > > //SELECT InCompleOrderId > > > // , 1 AS 'Status' > > > //FROM InCompleOrders > > > //WHERE Reference = 'abc' > > > > return bo; > > > > } > > > > Also be able to do the same for: > > > > var baseOrder = repository.get base order; > > > if baseOrder type is InCompleteOrder > > > then will select from InCompleteOrderItems table > > > > and vice versa. > > > > I am using NHibernate 2.1 and c# 3.0. Any help would be much > > > appretiated.- Tekst uit oorspronkelijk bericht niet weergeven - > > - Tekst uit oorspronkelijk bericht weergeven - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
