No, I did mean Many to One :-) The Domain Objects are Golfer and Address
and many Golfers can share the same Address. Per James
"i-think-you-mean-a-many-to-one-sir" G, this should be mapped as Many to
one. I am just not sure how to do it thru AutoMap conventions.
HTH
Ramana
namespace GolfHandicapManager.Core
{
public class Golfer : Entity
{
public Golfer() { }
[DomainSignature]
[NotNullNotEmpty]
public virtual string FirstName { get; set; }
[DomainSignature]
[NotNullNotEmpty]
public virtual string LastName { get; set; }
[NotNullNotEmpty]
public virtual string EmailAddress { get; set; }
public virtual string EmailAddress2 { get; set; }
public virtual string HomePhone { get; set; }
public virtual string CellPhone { get; set; }
public virtual Address Address { get; set; }
}
public class Address : Entity
{
public Address() { }
[DomainSignature]
public virtual string Addr1 { get; set; }
public virtual string Addr2 { get; set; }
[DomainSignature]
public virtual string City { get; set; }
public virtual string State { get; set; }
public virtual string Country { get; set; }
public virtual string ZipCode { get; set; }
}
}
On Wed, Feb 11, 2009 at 2:05 PM, Chris Marisic <[email protected]> wrote:
>
> Do you mean One to Many?
>
> convention.OneToManyConvention = m =>
> {
> m.Cascade.All();
> };
>
> On Feb 11, 1:58 pm, Ramana Kumar <[email protected]> wrote:
> > Hi
> > I am trying to use AutoMap to define behaviour for ManyToOne and I get
> the
> > following exception
> >
> > object references an unsaved transient instance - save the transient
> > instance before flushing:
> >
> > The relevant code is
> >
> > public class AutoPersistenceModelGenerator :
> IAutoPersistenceModelGenerator
> > {
> > public AutoPersistenceModel Generate()
> > {
> > AutoPersistenceModel mappings = AutoPersistenceModel
> > .MapEntitiesFromAssemblyOf<Golfer>()
> > .Where(GetAutoMappingFilter)
> > .WithConvention(GetConventions);
> > return mappings;
> > }
> >
> > private bool GetAutoMappingFilter(Type t)
> > {
> > return t.Namespace == "GolfHandicapManager.Core";
> > }
> > private void GetConventions(Conventions c)
> > {
> > c.GetPrimaryKeyNameFromType = type => "ROW_ID"; //DB has
> ROW_ID
> > as Primary Key
> > c.FindIdentity = type => type.Name == "ID"; // S#arp
> currently
> > uses "ID"
> > // Taken from Ayende Blog
> > c.GetForeignKeyNameOfParent = (type => type.Name + "_ID");
> > c.GetTableName = type =>
> > Inflector.Net.Inflector.Pluralize(type.Name);
> > c.IsBaseType = IsBaseTypeConvention;
> > // Convert PropertyName to Underscore
> > c.AddPropertyConvention(new
> > PascalToUnderscorePropertyConvention());
> > }
> >
> > I am assuming I have to do a "cascade=all" somewhere in there but do not
> > know how to do it thru a convention.
> >
> > Any pointers?
> > Thanks
> > Ramana
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---