With all due respect, this is not a NHibernate question, but a Windows Forms
one (i.e. it's exactly the same if the Contact property was mapped by NH or
created in memory)
And in any case the solution is probably within the WinForms domain
(creating a column that can be bound to an expression, I did that once but
can't find it now). I suggest you ask in a Winforms forum, or in
StackOverflow.

   Diego


On Sat, Feb 13, 2010 at 19:41, Gautam <[email protected]> wrote:

> Hi All,
>
> I am using FluentNHibernate and  have a mapping that contains
> components as well as other x-to-x relationships.
>
> Below is my code structure and you can see it's fairly
> straightforward.
>
> Since Contact is used in other tables I turned it into a Component.
> Also a person can have many employers (or none).
>
> What I am having trouble with is databinding this to a datagridview.
> Here's my code that gets all the persons and then binds it to a
> gridview.
>
>    private void FillDataGridView()
>    {
>      ISession session = Database.Current.Session;
>
>      this.PersonList = session.CreateCriteria<Person>()
>                          .List<Person>();
>
>      this.DataGridViewSearchMain.DataSource = this.PersonList;
>
>      session.Close();
>    }
>
> The problem is I want to treat the objects in my Person table as
> columns.  Here's what it looks like right now.
>
>  http://imgur.com/Fehsp.jpg
>
> Now I know about overriding ToString() but that's not what I want.  I
> would rather show each individual column from Contact
>
> or at least have some control over what to show.
>
>
> public class Person
> {
>  public virtual Guid PersonID { get; private set; }
>
>  public virtual string Name { get; set; }
>
>  public virtual Contact Contact { get; set; }
>
>  public virtual IList<Employer> Employers { get; set; }
> }
>
> public class PersonMap : ClassMap<Person>
> {
>  public PersonMap()
>  {
>    Id(x => x.PersonID)
>      .GeneratedBy.Guid();
>
>    Component(x => x.Contact);
>
>    HasManyToMany(x => x.Employers)
>      .Table("PersonEmployer")
>      .ParentKeyColumn("PersonID")
>      .ChildKeyColumn("EmployerID")
>      .Cascade.SaveUpdate();
>  }
> }
>
> public class Contact
> {
>  [DisplayName("E-mail")]
>  public virtual string Email { get; set; }
>
>  [DisplayName("Phone #")]
>  public virtual string Phone { get; set; }
> }
>
> public class ContactMap : ComponentMap<Contact>
> {
>  public ContactMap()
>  {
>    Map(x => x.Email);
>    Map(x => x.Phone);
>  }
> }
>
> --
> 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.

Reply via email to