我的 MassTransit 传奇只有一个字段无法正确映射。这是 -
public virtual IDictionary<string, string> Rows
{
get { return _rows; }
set { _rows = value; }
}
我试过用几种方法映射它 -
publich ProjCTSagaMap() // ctor for my ClassMap subclass
{
/*HasMany(x => x.Rows)
.AsMap("ProjectNumber")
.KeyColumns.Add("Row", mapping => mapping.Name("Row").SqlType("nvarchar").Not.Nullable())
.Cascade.AllDeleteOrphan()
.Table("ProjCtSagaRow");*/
HasMany(x => x.Rows)
.Table("ProjCtSagaRow")
.KeyColumn("CorrelationId")
.Element("Row")
.AsMap("ProjectNumber")
.Inverse();
}
我写了一个单元测试来测试映射 -
[Test] public void ProjCtSagaMapTest()
{
using (var session = Utility.CreateSession<ProjCtSaga, ProjCtSagaMap>())
{
new PersistenceSpecification<ProjCtSaga>(session)
.CheckReference(
i => i.Rows,
new Dictionary<string, string> { { "key", "value" } },
new DictionaryComparer<string, string>())
.VerifyTheMappings();
}
我不确定问题到底出在哪里,在映射中还是在测试中。单元测试中的实际错误是 -
NHibernate.MappingException occurred
Message=No persister for: System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Source=NHibernate
StackTrace:
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName, Object obj)
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at FluentNHibernate.Testing.PersistenceSpecification`1.TransactionalSave(Object propertyValue) in d:\Builds\FluentNH\src\FluentNHibernate\Testing\PersistenceSpecification.cs:line 79
InnerException:
有人可以解释如何使用 ClassMap 映射 IDictionary 并使用 PersistenceSpecification ... VerifyMappings() 测试该映射吗?
PS - FluentNHibernate 的版本是 1.3.0.717,NHibernate 的版本是 3.2.0.4000。我确实必须在本地编译它以进行一项次要且不相关的更改。
谢谢!
这是我现在得到的其余错误 -
System.FormatException : Failed to convert parameter value from a String to a Int32.
----> System.FormatException : Input string was not in a correct format.
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.GetCoercedValue()
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, ref _SqlRPC rpc)
at System.Data.SqlClient.SqlCommand.AddBatchCommand(String commandText, SqlParameterCollection parameters, CommandType cmdType)
at System.Data.SqlClient.SqlCommandSet.ExecuteNonQuery()
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatchWithTiming(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatch()
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at FluentNHibernate.Testing.PersistenceSpecification`1.TransactionalSave(Object propertyValue) in d:\Builds\FluentNH\src\FluentNHibernate\Testing\PersistenceSpecification.cs: line 80
at FluentNHibernate.Testing.PersistenceSpecification`1.VerifyTheMappings(T first) in d:\Builds\FluentNH\src\FluentNHibernate\Testing\PersistenceSpecification.cs: line 52
at Appalappa.Tests.ProjCtTests.ProjCtSagaMapTest() in ProjCtTests.cs: line 32
--FormatException
at System.Number.StringToNumber(String str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)