SubSonic Forums
All Your Database Are Belong To Us

One view, two objects.

Latest post 10-13-2008 3:57 AM by kianryan. 3 replies.
  • 10-12-2008 11:06 AM

    One view, two objects.

    Hi there,

    I'm attempting to use the repository pattern with a new project, and I'm looking for an efficent way of populating two distinct objects from a single view.  The two objects are related, and one sits as a property of the other.  I've got no problem manually binding them, but it's increadibly tedious to have to map all the attributes to the two distinct objects manually.


    Is there any way to effect the following:

                CompleteCustomer completeCustomer = new Select()
                    .From(CompleteCustomer.Schema)
                    .Where(CompleteCustomer.Columns.Email).IsEqualTo(email)
                    .Where(CompleteCustomer.Columns.Password).IsEqualTo(password)
                    .ExecuteSingle()
                    .ExecuteSingle()
    

    where customer and person are inner joined in the view?

    I realise that I may be into the realms of fantasy, but any heads up would be most welcome.

    Thanks
    Kian Ryan

  • 10-13-2008 12:22 AM In reply to

    Re: One view, two objects.

    From what I understand you are trying to do I don't think its possible to do with SubSonic maybe something like NHibernate can do this.

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 10-13-2008 2:32 AM In reply to

    Re: One view, two objects.

    Could a bit of reflection help ?

    This is a conversion from a VB project that does something very similar to what you are doing.

    public static void CopyPropertyValuesByName<T, T2>(ref T ObjFrom, T2 oBJtO)
    {
     Type iTypeFrom = typeof(T);
     Type iTypeTo = typeof(T2);

     Reflection.PropertyInfo[] pFrom = iTypeFrom.GetProperties();
     Reflection.PropertyInfo[] pTo = iTypeTo.GetProperties();
     PropertyInfo piTo = default(PropertyInfo);

     const BindingFlags FLAGS = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
     foreach (PropertyInfo piFrom in pFrom) {
      piTo = iTypeTo.GetProperty(piFrom.Name, FLAGS);
      if (piTo != null && !DBNull.Value.Equals(piFrom.Name)) {
       if (piTo.CanWrite && piFrom.CanRead) {
        piTo.SetValue(oBJtO, piFrom.GetValue(ObjFrom, null), null);
       }
      }
     }
    }

  • 10-13-2008 3:57 AM In reply to

    Re: One view, two objects.

    That's a great idea.  *facepalm*, I should have thought of that one earlier.

    I put it down to stress and pressing deadlines.  Many Thanks.

Page 1 of 1 (4 items) | RSS