Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';类型为';输入类型为';Domain.Entities.Request';以及类型为'的检查;Domain.Entities.Base';不支持_C#_.net_Linq_Api_Odata - Fatal编程技术网

C# ';类型为';输入类型为';Domain.Entities.Request';以及类型为'的检查;Domain.Entities.Base';不支持

C# ';类型为';输入类型为';Domain.Entities.Request';以及类型为'的检查;Domain.Entities.Base';不支持,c#,.net,linq,api,odata,C#,.net,Linq,Api,Odata,我得到了这个错误: 不支持输入类型为“Domain.Flood.Entities.Things.SomeObject”且检查类型为“Domain.Entities.Base”的“TypeIs”表达式。LINQ to Entities查询中仅支持实体类型和复杂类型 我正在尝试调用我的ODataAPI并扩展对象上的CreatedBy属性。CreatedBy属性位于基类中,是一种用户类型。因此,我的基类如下所示: [DataContract(Namespace = "http://schemas.mi

我得到了这个错误:

不支持输入类型为“Domain.Flood.Entities.Things.SomeObject”且检查类型为“Domain.Entities.Base”的“TypeIs”表达式。LINQ to Entities查询中仅支持实体类型和复杂类型

我正在尝试调用我的ODataAPI并扩展对象上的CreatedBy属性。CreatedBy属性位于基类中,是一种用户类型。因此,我的基类如下所示:

[DataContract(Namespace = "http://schemas.microsoft.com/ado/2007/08/dataservices")]
    public abstract class Base
    {    
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public string Description { get; set; }    

        private User createdBy;    
        [DataMember]
        public virtual User CreatedBy
        {
            get
            {
                return createdBy;
            }
            set
            {
                createdBy = value;
            }
        } 
    }
当我试图获取从基类继承的小部件时,我还想包含名为CreatedBy的用户对象,我得到了这个错误。如果我不展开CreatedBy对象,我就不会得到错误。奇怪的是,我的另一个用户属性不是在基类上,而是在我的SomeObject类AssignedTo中。如果我再进一步说,一切都很美好。因此,在基类上展开User对象,而不是bueno。将用户对象向上扩展几个级别,bueno

     {
         Container.SendingRequest += new EventHandler<SendingRequestEventArgs>(OnSendingRequest);
         ViewBag.Data = Container.SomeObject.Expand("Address, CreatedBy").ToList();
         return View();
     }
{
Container.SendingRequest+=新事件处理程序(OnSendingRequest);
ViewBag.Data=Container.SomeObject.Expand(“Address,CreatedBy”).ToList();
返回视图();
}
以下是堆栈跟踪:

Exception Details: System.Data.Services.Client.DataServiceClientException: <?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
 <m:code />
 <m:message xml:lang="en-US">An error has occurred.</m:message>
 <m:innererror>
   <m:message>The 'ObjectContent`1' type failed to serialize the response body for content type 'application/atom+xml; charset=utf-8'.</m:message>
   <m:type>System.InvalidOperationException</m:type>
   <m:stacktrace></m:stacktrace>
   <m:internalexception>
     <m:message>The 'TypeIs' expression with an input of type 'Domain.Flood.Entities.Things.SomeObject' and a check of type 'Domain.Entities.Base' is not supported. Only entity types and complex types are supported in LINQ to Entities queries.</m:message>
     <m:type>System.NotSupportedException</m:type>
     <m:stacktrace>   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.GetIsOrAsTargetType(ExpressionType operationType, Type toClrType, Type fromClrType)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.IsTranslator.TypedTranslate(ExpressionConverter parent, TypeBinaryExpression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConditionalTranslator.TypedTranslate(ExpressionConverter parent, ConditionalExpression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding&amp; binding)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression&amp; source, DbExpressionBinding&amp; sourceBinding, DbExpression&amp; lambda)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()&#xD;
  at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)&#xD;
  at System.Data.Entity.Core.Objects.ObjectQuery`1.&lt;&gt;c__DisplayClassb.&lt;GetResults&gt;b__a()&#xD;
  at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)&#xD;
  at System.Data.Entity.Core.Objects.ObjectQuery`1.&lt;&gt;c__DisplayClassb.&lt;GetResults&gt;b__9()&#xD;
  at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)&#xD;
  at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)&#xD;
  at System.Data.Entity.Core.Objects.ObjectQuery`1.&lt;System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator&gt;b__0()&#xD;
  at System.Lazy`1.CreateValue()&#xD;
  at System.Lazy`1.LazyInitValue()&#xD;
  at System.Lazy`1.get_Value()&#xD;
  at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()&#xD;
  at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
  at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)&#xD;
  at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)&#xD;
  at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)&#xD;
  at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext)&#xD;
--- End of stack trace from previous location where exception was thrown ---&#xD;
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xD;
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xD;
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult()&#xD;
  at System.Web.Http.WebHost.HttpControllerHandler.&lt;WriteBufferedResponseContentAsync&gt;d__14.MoveNext()</m:stacktrace>
   </m:internalexception>
 </m:innererror>
</m:error>
异常详细信息:System.Data.Services.Client.DataServiceClient异常:
发生了一个错误。
'ObjectContent'1'类型未能序列化内容类型'application/atom+xml'的响应正文;字符集=utf-8'。
System.InvalidOperationException异常
不支持输入类型为“Domain.Flood.Entities.Things.SomeObject”且检查类型为“Domain.Entities.Base”的“TypeIs”表达式。LINQ to Entities查询中仅支持实体类型和复杂类型。
System.NotSupportedException
在System.Data.Entity.Core.Objects.Elink.ExpressionConverter.GetIsOrAsTargetType(ExpressionType操作类型、类型toClrType、类型fromClrType)和#xD;
在System.Data.Entity.Core.Objects.Elink.ExpressionConverter.IsTranslator.TypedTranslate(ExpressionConverter父级,TypeBinaryExpression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter父级,expressionlinq)和xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)和#xD;
在System.Data.Entity.Core.Objects.Elink.ExpressionConverter.ConditionalTranslator.TypedTranslate(ExpressionConverter父级,ConditionalPression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter父级,expressionlinq)和xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)和#xD;
在System.Data.Entity.Core.Objects.elink.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter父级,MemberInitExpression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter父级,expressionlinq)和xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)和#xD;
在System.Data.Entity.Core.Objects.elink.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter父级,MemberInitExpression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter父级,expressionlinq)和xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)和#xD;
在System.Data.Entity.Core.Objects.elink.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter父级,MemberInitExpression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter父级,expressionlinq)和xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)和#xD;
在System.Data.Entity.Core.Objects.eliq.ExpressionConverter.TranslateLambda(LambdaExpression lambda,DbExpression input)和xD;
在System.Data.Entity.Core.Objects.eliq.ExpressionConverter.TranslateLambda(LambdaExpression lambda、DbExpression input、DbExpressionBinding&;binding)和xD;
位于System.Data.Entity.Core.Objects.Elink.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter父级,MethodCallExpression调用,DbExpression&;source,DbExpressionBinding&;sourceBinding,DbExpression&;lambda)和;
在System.Data.Entity.Core.Objects.Elink.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter父级,MethodCallExpression调用)和#xD;
位于System.Data.Entity.Core.Objects.Elink.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter父级、MethodCallExpression调用、SequenceMethod SequenceMethod SequenceMethod)和#xD;
在System.Data.Entity.Core.Objects.Elink.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter父级,MethodCallExpression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter父级,expressionlinq)和xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)和#xD;
在System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()和#xD;
在System.Data.Entity.Core.Objects.elink.elinkQueryState.GetExecutionPlan(可为null的`1 forMergeOption)&xD;
在System.Data.Entity.Core.Objects.ObjectQuery`1.c_uudisplayClassB.GetResultsb_uua()&xD;
在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 Func,IDbExecutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess)和#xD;
在System.Data.Entity.Core.Objects.ObjectQuery`1.c_uudisplayClassB.GetResultsb_uu9()&xD;
位于System.Data.Entity.SqlSer
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Base>(); //EF should crawl and configure all derived types as well.
}
modelBuilder.EntityType<SomeObject>().DerivesFromNothing();
modelBuilder.Entity<SomeObject>().DerivesFromNothing();