Hi José,
I'm using classmapping
public class UserMapping : ClassMapping<User>
but the "Set" method looks the same as doing it directly via the
mapper.Class method.
The difference I see, is the cascade that got added and the rest that
is ommited.
I have tried the code above, but I get the same results.
I have added below my entire code (entities, mapping and a bit of
dbinfo), that might help pinpoint my problem.
Thanks,
Ike
Here's the full code of the entities
public class User
{
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual Address Address { get; set; }
public virtual IList<Book> Recommendations { get; set; }
public virtual IList<Book> Queue { get; set; }
public virtual ICollection<Book> CurrentlyReading { get; set; }
public virtual ICollection<Subscription> Subscriptions { get;
set; }
}
public class Book
{
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual string ImageUrl { get; set; }
public virtual byte[] Image { get; set; }
public virtual string Author { get; set; }
}
public class Address
{
public virtual string Street { get; set; }
public virtual string Country { get; set; }
public virtual string City { get; set; }
public virtual string ZipCode { get; set; }
public virtual string HouseNumber { get; set; }
}
public class Subscription
{
public virtual long Id { get; set; }
public virtual int NumberOfPossibleBooksOut { get; set; }
public virtual decimal MonthlyCost { get; set; }
public virtual string CreditCard { get; set; }
public virtual User User { get; set; }
public virtual DateTime Start{ get; set; }
public virtual DateTime End { get; set; }
}
Here's my mapping code
public class UserMapping : ClassMapping<User>
{
public UserMapping()
{
Table("Users");
Id(x => x.Id, mapper =>
mapper.Generator(Generators.HighLow));
Property(x => x.Name, mapper =>
mapper.NotNullable(false));
Component(x => x.Address, mapper =>
{
mapper.Property(y =>
y.Street);
mapper.Property(y =>
y.Country);
mapper.Property(y =>
y.City);
mapper.Property(y =>
y.ZipCode);
mapper.Property(y =>
y.HouseNumber);
});
List(x => x.Queue, mapper =>
{
mapper.Table("UsersWaitingBooks");
mapper.Key(y =>
y.Column("`User`"));
mapper.Index(y =>
y.Column("`Index`"));
}, element =>
{
element.ManyToMany(y =>
{
y.Class(typeof (Book));
y.Column("Book");
});
element.Element(y =>
y.Column("Book"));
});
List(x => x.Recommendations, mapper =>
{
mapper.Table("UsersRecommendedBooks");
mapper.Key(y =>
y.Column("`User`"));
mapper.Index(y =>
y.Column("`Index`"));
}, element =>
{
element.ManyToMany();
element.Element(y
=> y.Column("Book"));
});
Set(x => x.CurrentlyReading, mapper =>
{
mapper.Cascade(Cascade.All);
mapper.Table("UsersReadingBooks");
mapper.Key(y =>
y.Column("`User`"));
}, element =>
{
element.Element(er =>
er.Column("Book"));
element.ManyToMany(z
=> z.ForeignKey("Book"));
});
Set(x => x.Subscriptions, mapper => mapper.Key(y =>
y.Column("`User`")), element => element.OneToMany());
}
}
public class SubscriptionMapping : ClassMapping<Subscription>
{
public SubscriptionMapping()
{
Table("Subscriptions");
Id(x => x.Id, mapper =>
mapper.Generator(Generators.HighLow));
Property(x => x.NumberOfPossibleBooksOut, mapper =>
mapper.NotNullable(false));
Property(x => x.CreditCard, mapper =>
mapper.NotNullable(false));
Property(x => x.MonthlyCost, mapper =>
mapper.NotNullable(false));
Property(x => x.Start, mapper =>
mapper.NotNullable(false));
Property(x => x.End, mapper =>
{
mapper.NotNullable(false);
mapper.Column("`End`");
});
ManyToOne(x => x.User, mapper =>
{
mapper.Column("`User`");
mapper.NotNullable(true);
});
}
}
public class BookMapping : ClassMapping<Book>
{
public BookMapping()
{
Table("Books");
Id(x => x.Id, mapper =>
mapper.Generator(Generators.HighLow));
Property(x => x.Name, mapper =>
mapper.NotNullable(false));
Property(x => x.ImageUrl, mapper =>
mapper.NotNullable(false));
Property(x => x.Image, mapper =>
{
mapper.NotNullable(false);
mapper.Length(131072);
});
Property(x => x.Author, mapper =>
mapper.NotNullable(false));
}
}
The database has UserS, BookS, UsersReadingBooks tables.
The UsersReadingBooks has 2 columns (Book, User)
On Aug 17, 2:56 pm, José F. Romaniello <[email protected]> wrote:
> ike, for me it seems that with your fluent code you are trying to map a
> "Dictionary" instead of a plain collection... something like this should
> work:
>
> mapper.Class<YourClass>(map => map.Set(p => p.CurrentlyReading,
> set => set.Cascade(Cascade.All),
> rel => rel.ManyToMany()));
On Aug 17, 2:56 pm, José F. Romaniello <[email protected]> wrote:
> ike, for me it seems that with your fluent code you are trying to map a
> "Dictionary" instead of a plain collection... something like this should
> work:
>
> mapper.Class<YourClass>(map => map.Set(p => p.CurrentlyReading,
> set => set.Cascade(Cascade.All),
> rel => rel.ManyToMany()));
--
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.