Exception on Mapper.Class<T>(Property)

98 views
Skip to first unread message

Matteo Migliore

unread,
May 25, 2011, 1:59:34 PM5/25/11
to ConfORM
Hi!

I'm wrapping ConfOrm to have the simplest code as possible to map an
entity.

I've this code on a "mapping class":
public class CustomerMapper : UniqueEntityMapping<Customer>
{
public CustomerMapper()
{
Property(p => p.FirstName, pm => { pm.Length(200);
pm.NotNullable(true); });
Property(p => p.LastName, pm => { pm.Length(250);
pm.NotNullable(true); });
}
}

I call this method in the base class of the "mapping class":
mapper.Class<TEntity>(c => c.Property(p => property.Key,
property.Value));

Where localProperty is a:
KeyValuePair<object, Action<IPropertyMapper>>.

I obtain this exception:
{"Value cannot be null.\r\nParameter name: localMember"}

StackTrace:
at ConfOrm.NH.PropertyPath..ctor(PropertyPath previousPath,
MemberInfo localMember)
at
ConfOrm.NH.CustomizersImpl.PropertyContainerCustomizer`1.Property[TProperty]
(Expression`1 property, Action`1 mapping)
at
EyeOpen.Data.Nhibernate.ConformModelMapping.<>c__DisplayClass6`1.<Register>b__3(IClassMapper`1
c) in E:\Dropbox\Eye.World\Business\Eye.Soft.v2\Dev\Hyperion\Main\Op
\Core\Proj\Sdk\DataAccessSdk\Src\Data.IntegrationTest\Nhibernate
\Mapping\Class\ConformModelMapping.cs:line 72
at ConfOrm.NH.Mapper.Class[TRootEntity](Action`1 customizeAction)
at EyeOpen.Data.Nhibernate.ConformModelMapping.Register[TEntity]
(IEntityMapping`1 entityConfiguration) in E:\Dropbox\Eye.World\Business
\Eye.Soft.v2\Dev\Hyperion\Main\Op\Core\Proj\Sdk\DataAccessSdk\Src
\Data.IntegrationTest\Nhibernate\Mapping\Class
\ConformModelMapping.cs:line 72
at EyeOpen.Data.IntegrationTest.Nhibernate.FooModelMapping..ctor()
in E:\Dropbox\Eye.World\Business\Eye.Soft.v2\Dev\Hyperion\Main\Op\Core
\Proj\Sdk\DataAccessSdk\Src\Data.IntegrationTest\Nhibernate
\FooModelMapping.cs:line 9
at
EyeOpen.Data.IntegrationTest.Nhibernate.NhibernateRepositoryTest.ClassInitialize(TestContext
testContext) in E:\Dropbox\Eye.World\Business\Eye.Soft.v2\Dev\Hyperion
\Main\Op\Core\Proj\Sdk\DataAccessSdk\Src\Data.IntegrationTest
\NhibernateRepositoryTest.cs:line 27

Any idea?

I'm doing this in the HSDK project:
http://goo.gl/EuejX

This code is not yet published.

Thanks a lot.

Fabio Maulo

unread,
May 25, 2011, 6:21:27 PM5/25/11
to codec...@googlegroups.com
The exception is clear.
What is not clear is UniqueEntityMapping<T>
btw you are wrongly creating an instance of PropertyPath passing a null as localMember
--
Fabio Maulo

Matteo Migliore

unread,
May 25, 2011, 6:26:41 PM5/25/11
to ConfORM
On May 26, 12:21 am, Fabio Maulo <fabioma...@gmail.com> wrote:
> The exception is clear.

Yes, it is :).

But I don't understand how to solve it.

> What is not clear is UniqueEntityMapping<T>
> btw you are wrongly creating an instance of PropertyPath passing a null as
> localMember

I can publish the latest version of source code.

Btw the base class of UniqueEntityMapping<T> is:
public abstract class EntityMapping<TEntity> :
IEntityMapping<TEntity>
where TEntity : IUniqueEntity
{
private readonly IDictionary<object, Action<IPropertyMapper>>
properties =
new Dictionary<object, Action<IPropertyMapper>>();

private readonly IDictionary<object, FluentPropertyMapper>
properties2 =
new Dictionary<object, FluentPropertyMapper>();

public IEnumerable<KeyValuePair<object, Action<IPropertyMapper>>>
Properties
{
get { return properties; }
}

public IEnumerable<KeyValuePair<object, FluentPropertyMapper>>
Properties2
{
get { return properties2; }
}

public Action<IIdMapper> IdMapper
{
get; private set;
}

public virtual MappingStrategies Strategy
{
get { return MappingStrategies.TablePerClass; }
}

public void Id(Action<IIdMapper> idMapper)
{
IdMapper = idMapper;
}

public FluentPropertyMapper
FluentProperty<TProperty>(Expression<Func<TEntity, TProperty>>
property)
{
var propertyMember =
typeof(TEntity)
.GetProperty(ExpressionHelper<TEntity>.GetPropertyName(property),
BindingFlags.Instance | BindingFlags.Public);

var fluentPropertyMapper = new FluentPropertyMapper(propertyMember,
new NHibernate.Cfg.MappingSchema.HbmProperty());

properties2.Add(property, fluentPropertyMapper);

return fluentPropertyMapper;
}

public void Property<TProperty>(Expression<Func<TEntity, TProperty>>
property, Action<IPropertyMapper> action)
{
properties.Add(property, action);
}
}

Thx again!


> On Wed, May 25, 2011 at 2:59 PM, Matteo Migliore
> <matteo.migli...@gmail.com>wrote:

Matteo Migliore

unread,
May 25, 2011, 6:34:22 PM5/25/11
to ConfORM
The problem could be in the first line of method Property of the class
PropertyContainerCustomizer<TEntity>:
MemberInfo localMember =
TypeExtensions.DecodeMemberAccessExpression<TEntity,
TProperty>(property);

But I checked, TypeExtensions works well.

Uhm...

On May 26, 12:26 am, Matteo Migliore <matteo.migli...@gmail.com>
wrote:

Matteo Migliore

unread,
May 26, 2011, 7:04:45 AM5/26/11
to ConfORM
I published the latest version here: http://goo.gl/DlErQ.

To test the code you have to go to EyeOpen.Data.IntegrationTest
project,
remove the comment ////INhibernateMapping mapping = new
FooModelMapping();
to use the FooModelMapping class and run the tests.

Thx!

On May 26, 12:34 am, Matteo Migliore <matteo.migli...@gmail.com>

Matteo Migliore

unread,
May 26, 2011, 10:38:52 AM5/26/11
to ConfORM
With a pair with Alessandro (Giorgetti) in Skype/TeamViewer all works
now.

On CodePlex you can find the latest version:
http://goo.gl/SXxNK

Now is possible to write this using ConfOrm:
var connection =
new NhibernateMicrosoftSqlServerConnection
{
DataSource = Connection.DataSource,
Catalog = string.Concat(Connection.Catalog),
IsTrustedConnection = Connection.IsTrustedConnection
};

INhibernateMapping mapping = new FooModelMapping();
////INhibernateMapping mapping = new FooFlatModelMapping();

configuration =
new NhibernateConfigurationBuilder()
.ProxyFactory<NHibernate.ByteCode.Castle.ProxyFactoryFactory>()
.Build(connection, mapping.GetMapping());

sessionFactory = configuration.BuildSessionFactory();

And the mapping:
public class CustomerMapper : UniqueEntityMapping<Customer>
{
public CustomerMapper()
{
Property(p => p.FirstName)
.Lenght(200)
.NotNullable(true);

Property(p => p.LastName)
.Lenght(200)
.NotNullable(true);
}
}

Great!

Fabio Maulo

unread,
May 26, 2011, 1:03:37 PM5/26/11
to codec...@googlegroups.com

Matteo Migliore

unread,
May 26, 2011, 1:52:54 PM5/26/11
to ConfORM
Oh god :(. U're right. I also read your post time ago... Grrr :).

Anyway, the scope of the mapping is have an abstract mapping system to
use with EF and NH.

On May 26, 7:03 pm, Fabio Maulo <fabioma...@gmail.com> wrote:
> It seems this:http://fabiomaulo.blogspot.com/2011/04/me-on-fluent-nhibernate.html
>
> On Thu, May 26, 2011 at 11:38 AM, Matteo Migliore <matteo.migli...@gmail.com

Fabio Maulo

unread,
May 26, 2011, 2:52:38 PM5/26/11
to codec...@googlegroups.com
That is what ConfORM mean.
--
Fabio Maulo

Matteo Migliore

unread,
May 26, 2011, 3:02:46 PM5/26/11
to ConfORM
I don't understand.

I'm creating a mapping system that could be used with EF and NH.

Do you plan to make ConfOrm separated to NH for a part to allow to use
it with EF also?

On May 26, 8:52 pm, Fabio Maulo <fabioma...@gmail.com> wrote:
> That is what ConfORM mean.
>
> On Thu, May 26, 2011 at 2:52 PM, Matteo Migliore
> <matteo.migli...@gmail.com>wrote:

Fabio Maulo

unread,
May 26, 2011, 4:25:08 PM5/26/11
to codec...@googlegroups.com
Since the beginning... that is the reason of the generic name not referring NH.
btw, EF4 has too few features to be used in a pure OO domain-model.
--
Fabio Maulo

Matteo Migliore

unread,
May 26, 2011, 4:36:12 PM5/26/11
to ConfORM
Oh wonderful! So cannot separate it from NH "ASAP"? I can use ConfOrm
with EF "now"
because for some project I don't need all feats of NH and of course I
would publish source
code of our progress (the team of HSDK where there's Alessandro
Giorgetti also).

On May 26, 10:25 pm, Fabio Maulo <fabioma...@gmail.com> wrote:
> Since the beginning... that is the reason of the generic name not referring
> NH.
> btw, EF4 has too few features to be used in a pure OO domain-model.
>
> On Thu, May 26, 2011 at 4:02 PM, Matteo Migliore
> <matteo.migli...@gmail.com>wrote:
> ...
>
> read more »

José F. Romaniello

unread,
May 26, 2011, 4:47:17 PM5/26/11
to codec...@googlegroups.com
In the current state of the art, i don't recommend you to build nothing on top of EF.
OTOH; I don't see why something like that will be useful. Each ORM has their own features for mapping... or at least EF has much less than NH, why you would abstract the mapping thing?
With the current ORMs in .Net you can't map a four-class domain as-is in two different ORMs.
This menas that if you want to change the orm you have to do major changes in your entities...

2011/5/26 Matteo Migliore <matteo....@gmail.com>

Fabio Maulo

unread,
May 26, 2011, 4:47:39 PM5/26/11
to codec...@googlegroups.com
Salutalo e digli che un solo sistema di query, che non da alcuna chance di essere ottimizzato, non é first class citizen
--
Fabio Maulo

Matteo Migliore

unread,
May 26, 2011, 6:13:17 PM5/26/11
to ConfORM
I know quite well EF to do this :). It can be used in simple
scenarios.

I want to abstract the mapping to switch from EF to NH with less
impact, not no impact.

Look at the project on CodePlex :)

On May 26, 10:47 pm, José F. Romaniello <jfromanie...@gmail.com>
wrote:
> In the current state of the art, i don't recommend you to build nothing on
> top of EF.
> OTOH; I don't see why something like that will be useful. Each ORM has their
> own features for mapping... or at least EF has much less than NH, why you
> would abstract the mapping thing?
> With the current ORMs in .Net you can't map a four-class domain as-is in two
> different ORMs.
> This menas that if you want to change the orm you have to do major changes
> in your entities...
>
> 2011/5/26 Matteo Migliore <matteo.migli...@gmail.com>

Matteo Migliore

unread,
May 26, 2011, 6:15:15 PM5/26/11
to ConfORM
Come dicevo, in scenari molto semplici anche EF IMHO può essere
adottato.

Certo, non è ancora neanche paragonabile a NH, ma ci sono alcune
similutidini che non mi sarei
aspettato prima di iniziarlo a studiare più approfonditamente :).

On May 26, 10:47 pm, Fabio Maulo <fabioma...@gmail.com> wrote:
> Salutalo e digli che un solo sistema di query, che non da alcuna chance di
> essere ottimizzato, non é first class citizen
>
> On Thu, May 26, 2011 at 5:36 PM, Matteo Migliore
> <matteo.migli...@gmail.com>wrote:
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages