本文整理汇总了C#中ModelMapper.CompileMappingForAllExplicitAddedEntities方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMapper.CompileMappingForAllExplicitAddedEntities方法的具体用法?C# ModelMapper.CompileMappingForAllExplicitAddedEntities怎么用?C# ModelMapper.CompileMappingForAllExplicitAddedEntities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelMapper
的用法示例。
在下文中一共展示了ModelMapper.CompileMappingForAllExplicitAddedEntities方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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.CompileMappingForAllExplicitAddedEntities();
}
示例2: ComponentMappingJustOnceDemo
public void ComponentMappingJustOnceDemo()
{
var mapper = new ModelMapper();
mapper.Component<Name>(comp =>
{
comp.Property(name => name.First);
comp.Property(name => name.Last);
});
mapper.Component<Address>(comp =>
{
comp.Property(address => address.CivicNumber);
comp.Property(address => address.Street);
});
mapper.Class<Person1>(cm =>
{
cm.Id(person => person.Id, map => map.Generator(Generators.HighLow));
cm.Property(person => person.Test);
cm.Component(person => person.Name, comp => { });
cm.Component(person => person.Address, comp => { });
});
var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities();
var hbmClass = hbmMapping.RootClasses[0];
var hbmComponents = hbmClass.Properties.OfType<HbmComponent>();
hbmComponents.Should().Have.Count.EqualTo(2);
hbmComponents.Select(x => x.Name).Should().Have.SameValuesAs("Name","Address");
}
示例3: ApplyTo
public void ApplyTo(Configuration configuration)
{
var mapper = new ModelMapper();
mapper.Class<Node>(node =>
{
node.Id(x => x.Id, map =>
{
map.Column("NodeId");
map.Generator(Generators.GuidComb);
});
node.Property(x => x.Name, map =>
{
map.Length(50);
map.Column("NodeName");
});
node.Bag(x => x.Connections, bag =>
{
bag.Key(key =>
{
key.Column("StartNodeId");
key.ForeignKey("FK_RelatedNode_Node_StartNodeId");
});
bag.Table("Connection");
bag.Cascade(Cascade.All.Include(Cascade.Remove));
bag.Fetch(CollectionFetchMode.Subselect);
});
});
mapper.Component<Connection>(connection =>
{
connection.Parent(x => x.Start);
connection.ManyToOne(x => x.End, manyToOne =>
{
manyToOne.Column("EndNodeId");
manyToOne.ForeignKey("FK_RelatedNode_Node_EndNodeId");
manyToOne.Cascade(Cascade.Persist);
manyToOne.NotNullable(true);
});
connection.Component(x => x.Quality, c => {});
});
mapper.Component<ConnectionQuality>(connectionQuality =>
{
connectionQuality.Property(x => x.UploadMbps);
connectionQuality.Property(x => x.DownloadMbps);
});
configuration.AddMapping(mapper.CompileMappingForAllExplicitAddedEntities());
}
示例4: ApplyTo
public void ApplyTo(Configuration configuration)
{
var mapper = new ModelMapper();
mapper.Class<Thing>(node =>
{
node.Id(x => x.Id, map =>
{
map.Column("TestModel1Id");
map.Generator(Generators.GuidComb);
});
node.Property(x => x.StringProperty, map => map.Length(50));
node.Property(x => x.BoolProperty);
node.Property(x => x.DateProperty);
node.Property(x => x.IntProperty);
node.Property(x => x.DecimalProperty);
});
configuration.AddMapping(mapper.CompileMappingForAllExplicitAddedEntities());
}
示例5: WhenMapHiloToDifferentSchemaThanClassThenIdHasTheMappedSchema
public void WhenMapHiloToDifferentSchemaThanClassThenIdHasTheMappedSchema()
{
var mapper = new ModelMapper();
mapper.Class<MyClass>(cm =>
{
cm.Schema("aSchema");
cm.Id(x => x.Id, idm => idm.Generator(Generators.HighLow, gm => gm.Params(new
{
table = "hilosequences",
schema="gSchema"
})));
});
var conf = new Configuration();
conf.DataBaseIntegration(x=> x.Dialect<MsSql2008Dialect>());
conf.AddDeserializedMapping(mapper.CompileMappingForAllExplicitAddedEntities(), "wholeDomain");
var mappings = conf.CreateMappings(Dialect.Dialect.GetDialect());
var pc = mappings.GetClass(typeof(MyClass).FullName);
((SimpleValue)pc.Identifier).IdentifierGeneratorProperties["schema"].Should().Be("gSchema");
}
示例6: GetMappingWithParentInCompo
private HbmMapping GetMappingWithParentInCompo()
{
var mapper = new ModelMapper();
mapper.Class<MyClass>(x =>
{
x.Id(c => c.Id);
x.Component(c => c.Compo);
x.Bag(c => c.Compos, cm => { });
});
mapper.Component<MyCompo>(x =>
{
x.Parent(c => c.AManyToOne);
x.Component(c => c.NestedCompo);
});
mapper.Component<MyNestedCompo>(x =>
{
x.Component(c => c.Owner);
x.Property(c => c.Something);
});
return mapper.CompileMappingForAllExplicitAddedEntities();
}
示例7: WhenDuplicateClassDoesNotDuplicateMapping
public void WhenDuplicateClassDoesNotDuplicateMapping()
{
var mapper = new ModelMapper();
mapper.Class<MyClass>(ca =>
{
ca.Id(x => x.Id, map =>
{
map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
});
ca.Property(x => x.Something);
});
mapper.Class<MyClass>(ca =>
{
ca.Id(x => x.Id, map =>
{
map.Column("MyClassId");
});
ca.Property(x => x.Something, map => map.Length(150));
});
var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities();
ModelIsWellFormed(hbmMapping);
}
示例8: AddDefaultMapping
protected virtual void AddDefaultMapping(NHibernate.Cfg.Configuration cfg)
{
ModelMapper mm = new ModelMapper();
mm.Class<ContentItem>(ContentItemCustomization);
mm.Class<ContentDetail>(ContentDetailCustomization);
mm.Class<DetailCollection>(DetailCollectionCustomization);
mm.Class<AuthorizedRole>(AuthorizedRoleCustomization);
var compiledMapping = mm.CompileMappingForAllExplicitAddedEntities();
var debugXml = compiledMapping.AsString();
cfg.AddDeserializedMapping(compiledMapping, "N2");
}
示例9: WhenMapPropertiesInTheBaseJumpedClassUsingMemberNameThenMapInInherited
public void WhenMapPropertiesInTheBaseJumpedClassUsingMemberNameThenMapInInherited()
{
// ignoring MyClass and using Inherited, as root-class, I will try to map all properties using the base class.
// NH have to recognize the case and map those properties in the inherited.
var inspector = new SimpleModelInspector();
inspector.IsEntity((type, declared) => type == typeof(Inherited));
inspector.IsRootEntity((type, declared) => type == typeof(Inherited));
var mapper = new ModelMapper(inspector);
mapper.Class<MyClass>(mc =>
{
mc.Id(x => x.Id);
mc.Property("Simple", map => map.Access(Accessor.Field));
mc.Property("ComplexType", map => map.Access(Accessor.Field));
mc.Bag<string>("Bag", y => y.Access(Accessor.Field));
mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field));
mc.List<string>("List", y => y.Access(Accessor.Field));
mc.Set<string>("Set", y => y.Access(Accessor.Field));
mc.Map<int, string>("Map", y => y.Access(Accessor.Field));
mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field));
mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field));
mc.Any<object>("Any", typeof (int), y => y.Access(Accessor.Field));
mc.Component("DynamicCompo", new {A = 2}, y => y.Access(Accessor.Field));
mc.Component<MyCompo>("Compo", y =>
{
y.Access(Accessor.Field);
y.Property(c => c.Something);
});
});
mapper.Class<Inherited>(mc => { });
HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities();
HbmClass hbmClass = mappings.RootClasses[0];
mappings.JoinedSubclasses.Should().Be.Empty();
hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any",
"DynamicCompo");
hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
}
示例10: WhenMapPropertiesInTheInheritedUsingMemberNameThenMapInBase
public void WhenMapPropertiesInTheInheritedUsingMemberNameThenMapInBase()
{
// without ignoring MyClass as root-class I will try to map all properties using the inherited class.
// NH have to recognize the case and, following Object-Relational-Mapping rules, map those properties in the base class.
var mapper = new ModelMapper();
mapper.Class<MyClass>(mc => mc.Id(x => x.Id));
mapper.JoinedSubclass<Inherited>(mc =>
{
mc.Property("Simple", map => map.Access(Accessor.Field));
mc.Property("ComplexType", map => map.Access(Accessor.Field));
mc.Bag<string>("Bag", y => y.Access(Accessor.Field));
mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field));
mc.List<string>("List", y => y.Access(Accessor.Field));
mc.Set<string>("Set", y => y.Access(Accessor.Field));
mc.Map<int, string>("Map", y => y.Access(Accessor.Field));
mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field));
mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field));
mc.Any<object>("Any", typeof(int), y => y.Access(Accessor.Field));
mc.Component("DynamicCompo", new { A = 2 }, y => y.Access(Accessor.Field));
mc.Component<MyCompo>("Compo", y =>
{
y.Access(Accessor.Field);
y.Property(c => c.Something);
});
});
var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
var hbmClass = mappings.RootClasses[0];
var hbmJoinedSubclass = mappings.JoinedSubclasses[0];
hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
hbmJoinedSubclass.Properties.Should().Be.Empty();
}
示例11: WhenMapPropertiesInTheInheritedThenMapInBase
public void WhenMapPropertiesInTheInheritedThenMapInBase()
{
// without ignoring MyClass as root-class I will try to map all properties using the inherited class.
// NH have to recognize the case and, following Object-Relational-Mapping rules, map those properties in the base class.
// Where needed, using the SimpleModelInspector, the user can revert this behavior checking the DeclaringType and ReflectedType of the persistent member.
var mapper = new ModelMapper();
mapper.Class<MyClass>(mc => mc.Id(x => x.Id));
mapper.JoinedSubclass<Inherited>(mc =>
{
mc.Property(x => x.Simple, map => map.Access(Accessor.Field));
mc.Property(x => x.ComplexType, map => map.Access(Accessor.Field));
mc.Bag(x => x.Bag, y => y.Access(Accessor.Field));
mc.IdBag(x => x.IdBag, y => y.Access(Accessor.Field));
mc.List(x => x.List, y => y.Access(Accessor.Field));
mc.Set(x => x.Set, y => y.Access(Accessor.Field));
mc.Map(x => x.Map, y => y.Access(Accessor.Field));
mc.OneToOne(x => x.OneToOne, y => y.Access(Accessor.Field));
mc.ManyToOne(x => x.ManyToOne, y => y.Access(Accessor.Field));
mc.Any(x => x.Any, typeof(int), y => y.Access(Accessor.Field));
mc.Component(x => x.DynamicCompo, new { A=2 }, y => y.Access(Accessor.Field));
mc.Component(x => x.Compo, y =>
{
y.Access(Accessor.Field);
y.Property(c => c.Something);
});
});
var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
var hbmClass = mappings.RootClasses[0];
var hbmJoinedSubclass = mappings.JoinedSubclasses[0];
hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
hbmClass.Properties.Select(p => p.Access).All(x=> x.Satisfy(access=> access.Contains("field.")));
hbmJoinedSubclass.Properties.Should().Be.Empty();
}