本文整理汇总了C#中ModelMapper.Class方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMapper.Class方法的具体用法?C# ModelMapper.Class怎么用?C# ModelMapper.Class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelMapper
的用法示例。
在下文中一共展示了ModelMapper.Class方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mapping
protected override void Mapping(Configuration config)
{
var mapper = new ModelMapper();
mapper.Class<Software>(map =>
{
map.Id(s => s.Id, o => o.Generator(Generators.GuidComb));
map.Property(s => s.Name, o =>
{
o.NotNullable(true);
o.Unique(true);
});
});
mapper.Class<AssignedSoftware>(map =>
{
map.Id(s => s.Key, o => o.Generator(Generators.Assigned));
map.Property(s => s.Name, o =>
{
o.NotNullable(true);
o.Unique(true);
});
});
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
config.AddMapping(mapping);
config.DataBaseIntegration(db => db.LogSqlInConsole = true);
}
示例2: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Order>(rc =>
{
rc.Table("Orders");
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.Set(x => x.OrderLines, m =>
{
m.Inverse(true);
m.Key(k =>
{
k.Column("OrderId");
k.NotNullable(true);
});
m.Cascade(Mapping.ByCode.Cascade.All.Include(Mapping.ByCode.Cascade.DeleteOrphans));
m.Access(Accessor.NoSetter);
}, m => m.OneToMany());
});
mapper.Class<OrderLine>(rc =>
{
rc.Table("OrderLines");
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.ManyToOne(x => x.Order, m => m.Column("OrderId"));
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例3: GetMappings
private HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<User>(rt =>
{
rt.Id(x => x.Id, map => map.Generator(Generators.Guid));
rt.Property(x => x.Name);
rt.Set(x => x.Roles, map =>
{
map.Table("UsersToRoles");
map.Inverse(true);
map.Key(km => km.Column("UserId"));
}, rel => rel.ManyToMany(mm =>
{
mm.Column("RoleId");
mm.ForeignKey("FK_RoleInUser");
}));
});
mapper.Class<Role>(rt =>
{
rt.Id(x => x.Id, map => map.Generator(Generators.Guid));
rt.Property(x => x.Name);
rt.Set(x => x.Users, map =>
{
map.Table("UsersToRoles");
map.Key(km => km.Column("RoleId"));
}, rel => rel.ManyToMany(mm =>
{
mm.Column("UserId");
mm.ForeignKey("FK_UserInRole");
}));
});
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
return mappings;
}
示例4: InitDbModel
public override void InitDbModel(ModelMapper mapper)
{
mapper.Class<Dashboard>(cfg => cfg.Table("UniUI_Dashboard"));
mapper.Class<Widget>(cfg => cfg.Table("UniUI_Widget"));
mapper.Class<Panel>(cfg => cfg.Table("UniUI_Panel"));
mapper.Class<WidgetParameter>(cfg => cfg.Table("UniUI_WidgetParameter"));
}
示例5: GetMappings
protected override HbmMapping GetMappings()
{
// The impl/mapping of the bidirectional one-to-many sucks but was provided as is
var mapper = new ModelMapper();
mapper.BeforeMapClass += (i, t, cm) => cm.Id(map =>
{
map.Column((t.Name + "Id").ToUpperInvariant());
map.Generator(Generators.HighLow, g => g.Params(new { max_lo = "1000" }));
});
mapper.Class<Customer>(ca =>
{
ca.Lazy(false);
ca.Id(x => x.Id, m => { });
ca.NaturalId(x => x.Property(c => c.Name, p => p.NotNullable(true)));
ca.Property(x => x.Address, p => p.Lazy(true));
ca.Set(c => c.Orders, c =>
{
c.Key(x => x.Column("CUSTOMERID"));
c.Inverse(true);
c.Cascade(Mapping.ByCode.Cascade.All);
}, c => c.OneToMany());
});
mapper.Class<Order>(cm =>
{
cm.Id(x => x.Id, m => { });
cm.Property(x => x.Date);
cm.ManyToOne(x => x.Customer, map => map.Column("CUSTOMERID"));
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例6: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Parent>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.List(x => x.Children,
m =>
{
m.Lazy(CollectionLazy.Extra);
m.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
m.Inverse(true);
},
relation => relation.OneToMany());
});
mapper.Class<Child>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.ManyToOne(x => x.Parent);
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例7: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Document>(rc =>
{
rc.Id(x => x.Id, idMapper => idMapper.Generator(Generators.Identity));
rc.ManyToOne(x => x.Blob, m =>
{
m.Cascade(Mapping.ByCode.Cascade.All);
});
rc.Property(x => x.Name);
});
mapper.Class<Blob>(map =>
{
map.Id(x => x.Id, idMapper => idMapper.Generator(Generators.Identity));
map.Property(x => x.Bytes, y =>
{
y.Column(x =>
{
x.SqlType("varbinary(max)");
x.Length(int.MaxValue);
});
y.Lazy(true);
});
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例8: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.BeforeMapClass += (inspector, type, map) => map.Id(x=> x.Generator(Generators.GuidComb));
mapper.Class<Foo>(mc =>
{
mc.Id(x => x.Id);
mc.Bag(x => x.Bars, map =>
{
map.Inverse(true);
map.Cascade(Mapping.ByCode.Cascade.All);
map.Key(km =>
{
km.Column("FooId");
km.OnDelete(OnDeleteAction.Cascade);
});
}, rel => rel.OneToMany());
});
mapper.Class<Bar>(mc =>
{
mc.Id(x => x.Id);
mc.ManyToOne(x=> x.Foo, map=> map.Column("FooId"));
});
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
return mappings;
}
示例9: GetMappings
private HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.BeforeMapClass += (mi, t, map) => map.Id(x => x.Generator(Generators.GuidComb));
mapper.Class<Parent>(rc =>
{
rc.Id(p => p.Id);
rc.Property(p => p.ParentCode, m => m.Unique(true));
rc.Property(p => p.Name);
rc.Bag(p => p.Children, m =>
{
m.Key(km => { km.Column(cm => cm.Name("ParentParentCode")); km.PropertyRef(pg => pg.ParentCode); });
m.Inverse(true);
m.Cascade(Mapping.ByCode.Cascade.Persist);
}, rel => rel.OneToMany());
});
mapper.Class<Child>(rc =>
{
rc.Id(p => p.Id);
rc.Property(p => p.Name);
rc.ManyToOne<Parent>(p => p.Parent, m => { m.Column("ParentParentCode"); m.PropertyRef("ParentCode"); });
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例10: Customize
private static void Customize(ModelMapper mapper)
{
mapper.Class<EntityBase>(map =>
{
map.Id(e => e.Id, id => id.Generator(Generators.HighLow));
map.Version(e => e.Version, d => { });
});
mapper.Class<Product>(map => map.Set(p => p.Customizations,
set => set.Cascade(Cascade.All),
rel => rel.ManyToMany()));
mapper.Class<Customization>(map => map.Set(p => p.PossibleValues,
set => set.Cascade(Cascade.All),
rel => rel.Element()));
mapper.Class<Order>(map =>
{
map.Set(p => p.Items, set =>
{
set.Cascade(Cascade.All);
set.Inverse(true);
});
map.ManyToOne(o => o.Payment, o => o.Cascade(Cascade.All));
});
}
示例11: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Author>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
rc.Property(x => x.Name);
rc.ManyToOne(x => x.Publisher, m => m.Cascade(Mapping.ByCode.Cascade.All));
rc.Set(x => x.Books, m =>
{
m.Cascade(Mapping.ByCode.Cascade.All);
m.Lazy(CollectionLazy.Lazy);
}, r => r.OneToMany());
});
mapper.Class<Book>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
rc.Property(x => x.Title);
rc.ManyToOne(x => x.Author);
});
mapper.Class<Publisher>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
rc.Property(x => x.Name);
rc.Set(x => x.Authors, m => m.Cascade(Mapping.ByCode.Cascade.All), r => r.OneToMany());
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例12: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Employee>(mc =>
{
mc.Id(x => x.Id, map =>
{
map.Generator(Generators.Identity);
map.Column("Id");
});
mc.ManyToOne<EmployeeInfo>(x => x.Info, map =>
{
map.Column("Info_id");
map.Unique(true);
map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
});
});
mapper.Class<EmployeeInfo>(cm =>
{
cm.Id(x => x.Id, m =>
{
m.Generator(Generators.Identity);
m.Column("Id");
});
cm.OneToOne<Employee>(x => x.EmployeeDetails, map =>
{
map.PropertyReference(x => x.Info);
});
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例13: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Employee>(mc =>
{
mc.Id(x => x.Id, map =>
{
map.Generator(Generators.Identity);
map.Column("Id");
});
mc.OneToOne<EmployeeInfo>(x => x.Info, map =>
{
map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
map.Constrained(false);
});
});
mapper.Class<EmployeeInfo>(mc =>
{
mc.Id(x => x.Id, map =>
{
map.Generator(Generators.Foreign<EmployeeInfo>(x => x.EmployeeDetails));
map.Column("Id");
});
mc.OneToOne<Employee>(x => x.EmployeeDetails, map =>
{
map.Constrained(true);
});
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例14: SpecifiedForeignKeyNameInByCodeMappingIsUsedInGeneratedSchema
public void SpecifiedForeignKeyNameInByCodeMappingIsUsedInGeneratedSchema()
{
var mapper = new ModelMapper();
// Generates a schema in which a Person record cannot be created unless an Employee
// with the same primary key value already exists. The Constrained property of the
// one-to-one mapping is required to create the foreign key constraint on the Person
// table, and the optional ForeignKey property is used to name it; otherwise a
// generated name is used
mapper.Class<Person>(rc =>
{
rc.Id(x => x.Id, map => map.Generator(Generators.Foreign<Employee>(p => p.Person)));
rc.Property(x => x.Name);
rc.OneToOne(x => x.Employee, map =>
{
map.Constrained(true);
map.ForeignKey(ForeignKeyName);
});
});
mapper.Class<Employee>(rc =>
{
rc.Id(x => x.Id);
rc.OneToOne(x => x.Person, map => { });
});
var script = new StringBuilder();
var cfg = new Configuration();
cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
new SchemaExport(cfg).Execute(s => script.AppendLine(s), false, false);
script.ToString().Should().Contain(string.Format("constraint {0}", ForeignKeyName));
}
示例15: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Employee>(mc =>
{
mc.Id(x => x.Id, map =>
{
map.Generator(Generators.Identity);
map.Column("Id");
});
mc.ManyToOne<EmployeeInfo>(x => x.Info, map =>
{
// Columns have to be declared first otherwise other properties are reset.
map.Columns(x => { x.Name("COMP_ID"); },
x => { x.Name("PERS_ID"); });
map.Unique(true);
map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
map.NotFound(NotFoundMode.Exception);
});
});
mapper.Class<EmployeeInfo>(mc =>
{
mc.ComponentAsId<EmployeeInfo.Identifier>(x => x.Id, map =>
{
map.Property(x => x.CompanyId, m => m.Column("COMPS_ID"));
map.Property(x => x.PersonId, m => m.Column("PERS_ID"));
});
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}