This question is locked. New answers and comments are not allowed.
We have a series of persistent classes all of which have a Collection called Messages which is a collection of Msg entities. Here is our fluent MetadataSource class that uses one sided associations:
When this runs and we add msg to either Messages collection the field created in the Message table only contains null values. Eliminating the mapping in either msg user entity fixes the problem. Or changing the name of one of the Associations also resolves the problem but then we get one column in the Message tabgle for each entity class that has Messages.
I believe that there must be a workaround (perhaps with inheritance???) but have not been able to get it to work so far.
List<
MappingConfiguration
> configurations = new List<
MappingConfiguration
>();
//here is the Message mapping
MappingConfiguration<
Msg
> msgConfiguration = new MappingConfiguration<
Msg
>();
msgConfiguration.MapType(x => new
{
EntityId = x.EntityId,
MessageText = x.MessageText,
RowVersion = x.RowVersion,
}).ToTable("Message");
msgConfiguration.HasProperty(x => x.EntityId).IsIdentity(KeyGenerator.Guid);
msgConfiguration.HasProperty(x => x.RowVersion).IsVersion();
//here is one entity that has a IList<
Msg
> property called Messages
MappingConfiguration<
MsgUser
> msgUserConfiguration =
new MappingConfiguration<
MsgUser
>();
msgUserConfiguration.MapType(x => new
{
EntityId = x.EntityId,
UserName = x.UserName,
RowVersion = x.RowVersion,
}).ToTable("MessageUser");
msgUserConfiguration.HasProperty(x => x.RowVersion).IsVersion();
msgUserConfiguration.HasProperty(x => x.EntityId).IsIdentity(KeyGenerator.Guid);
msgUserConfiguration.HasAssociation(p => p.Messages).ToColumn("MsgUserId");
//here is another entity that has a IList<
Msg
> property called Messages
MappingConfiguration<
AnotherMsgUser
> anotherMsgUserConfiguration =
new MappingConfiguration<
AnotherMsgUser
>();
anotherMsgUserConfiguration.MapType(x => new
{
EntityId = x.EntityId,
MessageText = x.SomeData,
RowVersion = x.RowVersion
}).ToTable("AnotherMessageUser");
anotherMsgUserConfiguration.HasProperty(x => x.RowVersion).IsVersion();
anotherMsgUserConfiguration.HasProperty(x => x.EntityId).IsIdentity(KeyGenerator.Guid);
anotherMsgUserConfiguration.HasAssociation(p => p.Messages).ToColumn("MsgUserId");
//finally we add the configs to the configuration
configurations.Add(msgUserConfiguration);
configurations.Add(msgConfiguration);
configurations.Add(anotherMsgUserConfiguration);
When this runs and we add msg to either Messages collection the field created in the Message table only contains null values. Eliminating the mapping in either msg user entity fixes the problem. Or changing the name of one of the Associations also resolves the problem but then we get one column in the Message tabgle for each entity class that has Messages.
I believe that there must be a workaround (perhaps with inheritance???) but have not been able to get it to work so far.