I think we all know what you're trying to achieve, it's just not a very good
idea to do it in an entity. It may not even be possible to do that kind of
mapping with NHibernate. I don't know because it's never something that I
would consider doing. If it's some obtuse requirement of a service you have
no control over, then I'd personally create a DTO that interacts with it
that implements the appropriate behavior, and map between a properly
designed model and that DTO. Don't try to bring that mess down into the
model too.

On Wed, Mar 25, 2009 at 3:55 PM, Joshua <[email protected]> wrote:

>
> I think my design is so odd to you that I'm going to simplify
> further.  One major question I have is how to implement explicit
> interface implementations.  My entity must implement two interfaces
> with the same name in order to interact with the rest of the domain
> for which the design is not up to me.  I must persist all of the
> relevant data.  Here is my updated domain and skeletal mapping.
> Please recommend how you were persist the "Foo" properties using
> NHibernate, however seems best to you.
>
>    public interface IFoo1
>    {
>        string Foo
>        {
>            get;
>            set;
>        }
>
>    }
>
>    public interface IFoo2
>    {
>        string Foo
>        {
>            get;
>            set;
>        }
>
>    }
>
>    public class ConcreteFoo : IFoo1, IFoo2
>     {
>        public virtual int Id
>        {
>            get;
>            set;
>        }
>
>         string IFoo1.Foo
>        {
>            get;
>            set;
>        }
>
>        string IFoo2.Foo
>        {
>            get;
>            set;
>         }
>    }
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> assembly="MappingTests" namespace="MappingTests">
>  <class name="ConcreteFoo">
>    <id name="Id">
>      <generator class="identity" />
>    </id>
>   </class>
> </hibernate-mapping>
>
> [TestFixture]
>    public class FooTests
>    {
>        [Test]
>        public void Test()
>        {
>            Configuration cfg = new Configuration();
>            cfg = cfg.Configure();
>            ISessionFactory factory = cfg.BuildSessionFactory();
>            using (ISession session = factory.OpenSession())
>            {
>                new SchemaExport(cfg).Execute(false, true, false,
> true, session.Connection, null);
>
>                ConcreteFoo foo = new ConcreteFoo();
>                 ((IFoo1)foo).Foo = "foo";
>
>                session.Save(foo);
>            }
>        }
>    }
>
> Thanks.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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