Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Summary
- {
- public int id {get; protected set;}
- public IList<Detail> Details {get; protected set;}
- }
- public class Detail
- {
- public int id {get; protected set;}
- public string ItemName {get; set;}
- /* public Summary Owner {get; protected set;} */ //I think this might be needed for bidirectional mapping?
- }
- public class SummaryMap : ClassMap<Summary>
- {
- public SummaryMap()
- {
- Id(x => x.ID);
- HasMany<Detail>(x => x.Details);
- }
- }
- public class DetailMap : ClassMap<Detail>
- {
- public DetailMap()
- {
- Id(x => x.ID);
- Map(x => x.ItemName).CanNotBeNull();
- }
- }
- public class Detail
- {
- public int id { get; protected set; }
- public string ItemName { get; set; }
- // Renamed to use same column name as specified in the mapping of Summary.Details
- public Summary Summary {get; set;}
- }
- public class Summary
- {
- public Summary()
- {
- Details = new List<Detail>();
- }
- public int id { get; protected set; }
- public IList<Detail> Details { get; protected set; }
- }
- public class DetailMap : ClassMap<Detail>
- {
- public DetailMap()
- {
- Id(x => x.id)
- .GeneratedBy.Native();
- Map(x => x.ItemName)
- .CanNotBeNull();
- References<Summary>(x => x.Summary)
- // If you don't want to rename the property in Summary,
- // you can do this instead:
- // .TheColumnNameIs("Summary_id")
- .CanNotBeNull();
- }
- }
- public class SummaryMap : ClassMap<Summary>
- {
- public SummaryMap()
- {
- Id(x => x.id)
- .GeneratedBy.Increment();
- HasMany<Detail>(x => x.Details)
- .IsInverse()
- .AsBag(); // Use bag instead of list to avoid index updating issues
- }
- }
Add Comment
Please, Sign In to add comment