RIA Services不支持由NHibernate映射属性修饰的实体?

时间:2009-10-21 09:20:57

标签: silverlight nhibernate nhibernate-mapping wcf-ria-services

我正在开发一个项目,其中实体由NHibernate映射属性修饰,例如[Property]和[Class]。不幸的是,RIAServices似乎不支持大多数这些属性,当RIAServices尝试生成Silverlight客户端代码时会导致失败。

当我尝试构建一个使用[Class]或[Property]属性修饰的实体的DomainService时,我收到一个带有以下错误消息的ArgumentNullException:

Error   2   The "CreateRiaClientFilesTask" task failed unexpectedly.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: TypeName
at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
at NHibernate.Mapping.Attributes.ClassAttribute.get_NameType()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at System.Web.DomainServices.Tools.StandardCustomAttributeBuilder.GetPropertyValues(IEnumerable`1 propertyMaps, Attribute attribute)
at System.Web.DomainServices.Tools.StandardCustomAttributeBuilder.GetAttributeDeclaration(Attribute attribute)
at System.Web.DomainServices.Tools.CustomAttributeGenerator.GenerateCustomAttributes(ClientProxyGenerator proxyGenerator, CodeTypeDeclaration referencingType, IEnumerable`1 attributes, CodeCommentStatementCollection comments)
at System.Web.DomainServices.Tools.CustomAttributeGenerator.GenerateCustomAttributes(ClientProxyGenerator proxyGenerator, CodeTypeDeclaration referencingType, IEnumerable`1 attributes, CodeAttributeDeclarationCollection outputCollection, CodeCommentStatementCollection comments)
at System.Web.DomainServices.Tools.EntityProxyGenerator.Generate()
at System.Web.DomainServices.Tools.ClientProxyGenerator.GenerateProxyClass(String& generatedCode)
at System.Web.DomainServices.Tools.CreateRiaClientFilesTask.GenerateClientProxies()
at System.Web.DomainServices.Tools.CreateRiaClientFilesTask.Execute()
at Microsoft.Build.Framework.ITask.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)  SL 

我知道使用Fluent NHibernate应该可以解决这个问题,因为它不需要NHibernate依赖,但我想先确保在转向Fluent NHibernate之前没有任何其他解决方案。有关解决这个问题的任何想法吗?

3 个答案:

答案 0 :(得分:2)

正如我在评论中提到的那样,问题在于NHibernate在代码生成过程中出现问题。如果你真的想使用这些属性我会建议获取NHibernate源代码并尝试将VS调试器附加到正在进行代码生成的VS实例上,这可能会帮助你找出它失败的原因。

可能更好的方法是关注this post by Brada on using NHibernate with RIA Serviceswatching this screencast on NHibernate with RIA Services。这两个地方似乎都有他们合作的工作实例,所以也许从那里开始,而不是沿着你走的路走下去。

答案 1 :(得分:0)

您可以向实体添加预处理程序指令,以便在为silverlight编译时缺少属性。

#if SILVERLIGHT
//nothing
#else
[class]
#endif
public class entity{
}

答案 2 :(得分:0)

我们遇到了同样的问题。解决方案:摆脱属性,只使用XML进行映射。