You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Test]
public void CanOverrideIdProperty()
{
var model = AutoMap.Source(new StubTypeSource(new[] { typeof(EntityWithAlternateIdProperty) }))
.Override<EntityWithAlternateIdProperty>(o =>
{
o.Id(e => e.AlternateId);
});
HibernateMapping hibernateMapping = model.BuildMappings().First();
ClassMapping classMapping = hibernateMapping.Classes.First();
((IdMapping)classMapping.Id).Name.ShouldEqual("AlternateId");
}
public class EntityWithAlternateIdProperty
{
public int Id { get; set; }
public int AlternateId { get; set; }
public string Name { get; set; }
}
It seems that AutoMapper#TryMapProperty considers only whether or not the property has already been seen, rather than considering the type of mappings being generated by the rule. The sequence of events seems to be something like:
Override is applied, creating an IdMapping referring to AlternateId and applied at Layer.Defaults. AlternateId is marked as 'seen'.
Begins applying defaults. Properties are iterated.
The Id property is encountered. It has not yet been mapped, so the mapping steps are run against it.
IdentityStep creates an IdMapping referring to Id and applies it at Layer.Defaults. This obliterates the IdMapping created by the override.
Adding o.Map(e => e.Id); to the override works around the problem because it prevents IdentityStep being executed for that property.
I would expect overrides to be applied at Layer.UserSupplied but this does not appear to be the case. Is this a bug, or intended behaviour?
The text was updated successfully, but these errors were encountered:
I wrote the test against 30edae2, which was the tip of master at the time (29/01/2015?). We initially discovered the bug in the 1.3.0.734 version of the package.
I wrote the test against 30edae2 30edae2,
which was the tip of master at the time (29/01/2015?). We initially
discovered the bug in the 1.3.0.734 version of the package.
Thanks!
—
Reply to this email directly or view it on GitHub #299 (comment)
.
The following test fails:
It seems that AutoMapper#TryMapProperty considers only whether or not the property has already been seen, rather than considering the type of mappings being generated by the rule. The sequence of events seems to be something like:
Adding
o.Map(e => e.Id);
to the override works around the problem because it prevents IdentityStep being executed for that property.I would expect overrides to be applied at Layer.UserSupplied but this does not appear to be the case. Is this a bug, or intended behaviour?
The text was updated successfully, but these errors were encountered: