1 Replies - 1090 Views - Last Post: 13 September 2011 - 03:25 PM Rate Topic: -----

#1 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1175
  • View blog
  • Posts: 1,661
  • Joined: 24-August 11

Fluent NHibernate use object as attribute?

Posted 13 September 2011 - 01:53 PM

I'm new to Fluent NHibernate (or to ORMs in general for that matter), and I'm in a philosophical standstill (okay, maybe that's a BIT dramatic)...

I'm writing a module that will allow a manager to delegate reports to his or her direct reports. Managers and Delegates are both instances of Employee:
public class Employee : IPersistable
    {
        public virtual string EmployeeId { get; set; }
        public virtual DateTime AsOfDate { get; set; }
        public virtual string FirstName { get; set; }
        public virtual string Middle { get; set; }
        public virtual string LastName { get; set; }
        public virtual string CompanyNumber { get; set; }
        public virtual string JobNumber { get; set; }
        public virtual string JobTitle { get; set; }
        public virtual string Division { get; set; }
        public virtual DateTime EmploymentDate { get; set; }
        public virtual SupportingData Rate { get; set; }
        public virtual SupportingData Status { get; set; }
        public virtual int SalaryGrade { get; set; }
        public virtual string Email { get; set; }
        public virtual string SupervisorId { get; set; }
        public virtual string UserName { get; set; }
        public virtual IList<Employee> Employees { get; set; }
    }



The ReportDelegation table has a ManagerId, DelegateId, ReportId, and DateCreated.

My conundrum is whether, in my fluent ReportDelegation class, to go with:
 public class ReportDelegation : IPersistable
    {
        public virtual Employee Manager { get; set; }
        public virtual Employee Recipient { get; set; }
        public virtual ReportInfo ReportInfo { get; set; }
        public virtual DateTime CreateDate { get; set; }
    }



OR...
public class ReportDelegation : IPersistable
    {
        public virtual string ManagerId { get; set; }
        public virtual string RecipientId { get; set; }
        public virtual int ReportId { get; set; }
        public virtual DateTime CreateDate { get; set; }
    }



I would rather do it the first way, so that I can pass the entire object around and pull attributes as needed. However, I don't know how to set up the mapping between the defined attributes and the DB columns. The lure of the second method is that all I need is:
public class ReportDelegationMap : ClassMap<ReportDelegation>
    {
        public ReportDelegationMap()
        {
            CompositeId()
                .KeyProperty(x => x.ManagerId, "Manager_EmpId")
                .KeyProperty(x => x.RecipientId, "Delegate_EmpId")
                .KeyProperty(x => x.ReportId, "ReportID");
            Map(x => x.CreateDate)
                .Column("DateCreated");
        }
    }



Again, I feel like the first way, using object instances, is the better way to do it. If so, how do I map to my DB table?

Is This A Good Question/Topic? 0
  • +

Replies To: Fluent NHibernate use object as attribute?

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1175
  • View blog
  • Posts: 1,661
  • Joined: 24-August 11

Re: Fluent NHibernate use object as attribute?

Posted 13 September 2011 - 03:25 PM

Well, I'm an idiot.
public ReportDelegationMap()
        {
            CompositeId()
                .KeyProperty(x => x.Manager.EmployeeId, "Manager_EmpId")
                .KeyProperty(x => x.Recipient.EmployeeId, "Delegate_EmpId")
                .KeyProperty(x => x.ReportInfo.Id, "ReportID");
            Map(x => x.CreateDate)
                .Column("DateCreated");
        }



It helps if you use the object's attribute name, in case any of you were wondering... If intellisense likes it, then so do I!

Now I just have to teach the web service what an Employee is... :/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1