English 中文(简体)
Return base class in LINQ for stored procedure causes stackoverflow
原标题:

I have quite complex SP which returns base class (basecontent). I have inheritence with about 30+ child classes (like "page", "news", etc).

When I return other types from SP everything works fine, but this one drives me crazy. I am quite experienced with LINQ and already tryied to recreate SP, verified outout, etc. But this call fails to Stackoverflow exception even when number of returning rows is zero.

I have workaround - when I join it with another table, which has some statistics about content and do not have any inheritance, than I am able to go to content table using C# and take data, but this is significant performance degradation for me.

So far, my main guess is that something wrong with my inheritance mapping. Here is xml for this class:

<Table Name="dbo.baseContent" Member="baseContents">
    <Type Name="baseContent" Id="ID50" InheritanceCode="1" IsInheritanceDefault="true">
      <Column Name="Id" Type="System.Int64" DbType="BigInt NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
      <Column Name="Type" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" IsDiscriminator="true" />
      <Column Name="Status" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
      <Column Name="UniqueId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
      <Column Name="LastChanged" Member="LastChangedUTC" Storage="_LastChanged" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" UpdateCheck="Never" />
      <Column Name="Title" Modifier="Virtual" Type="System.String" DbType="NVarChar(255) NOT NULL" CanBeNull="false" />
      <Column Name="Version" Type="System.Int64" DbType="Bigint" CanBeNull="true" UpdateCheck="Never" />
      <Column Name="Tags" Type="System.String" DbType="NVarchar(255)" CanBeNull="false" />
      <Column Name="baseOwnerId" Type="System.Int64" DbType="BigInt NOT NULL" CanBeNull="true" />
      <Column Name="Views" Type="System.Int32" DbType="int" CanBeNull="false" />
      <Column Name="VotesValue" Type="System.Int32" DbType="int" CanBeNull="true" />
      <Column Name="Clicks" Type="System.Int32" DbType="int" CanBeNull="true" UpdateCheck="Never" />
      <Column Name="IsHidden" Type="System.Boolean" DbType="bit" CanBeNull="false" />
      <Column Name="IsFeatured" Type="System.Boolean" DbType="bit" CanBeNull="false" />
      <Column Name="IsAdvertising" Type="System.Boolean" DbType="bit" CanBeNull="false" />
      <Column Name="LoyaltyPoints" Type="System.Int32" DbType="int" CanBeNull="true" />
      <Column Name="CreatedDate" Type="System.DateTime" DbType="datetime" CanBeNull="true" />
      <Column Name="ViewsDetails" Type="System.Int32" DbType="int" CanBeNull="true" UpdateCheck="Never" />
      <Association Name="baseContent_baseDictionary" Member="baseDictionary" Storage="_baseDictionaries" ThisKey="Id" OtherKey="ContentId" Type="baseDictionary" Cardinality="One" />
      <Association Name="baseContent_tTopic" Member="tTopic" ThisKey="Id" OtherKey="ContentId" Type="tTopic" Cardinality="One" />
      <Association Name="baseContent_baseFile" Member="baseFile" Storage="_baseFiles" ThisKey="Id" OtherKey="ContentId" Type="baseFile" Cardinality="One" />
      <Association Name="baseContent_tLink" Member="tLink" ThisKey="Id" OtherKey="ContentId" Type="tLink" Cardinality="One" />
      <Association Name="baseContent_tNews" Member="tNews" ThisKey="Id" OtherKey="ContentId" Type="tNews" Cardinality="One" />
      <Association Name="baseContent_tModule" Member="tModule" ThisKey="Id" OtherKey="ContentId" Type="tModule" Cardinality="One" />
      <Association Name="baseContent_tPage" Member="tPage" ThisKey="Id" OtherKey="ContentId" Type="tPage" Cardinality="One" />
      <Association Name="baseContent_tOwner" Member="tOwner" Storage="_tOwners" ThisKey="Id" OtherKey="ContentId" Type="tOwner" Cardinality="One" />
      <Association Name="baseContent_tMessage" Member="tMessage" ThisKey="Id" OtherKey="ContentId" Type="tMessage" Cardinality="One" />
      <Association Name="baseContent_tTheme" Member="tTheme" Storage="_tTemplates" ThisKey="Id" OtherKey="ContentId" Type="tTheme" Cardinality="One" />
      <Association Name="baseContent_Tags_baseContent" Member="Tags_baseContents" ThisKey="Id" OtherKey="ContentId" Type="Tags_baseContent" />
      <Association Name="baseContent_tGoodie" Member="tGoodie" ThisKey="Id" OtherKey="ContentId" Type="tGoodie" Cardinality="One" />
      <Association Name="baseContent_tModuleSkin" Member="tModuleSkin" ThisKey="Id" OtherKey="ContentId" Type="tModuleSkin" Cardinality="One" />
      <Association Name="baseContent_tLocation" Member="tLocation" ThisKey="Id" OtherKey="ContentId" Type="tLocation" Cardinality="One" />
      <Association Name="baseContent_tEvent" Member="tEvent" ThisKey="Id" OtherKey="ContentId" Type="tEvent" Cardinality="One" />
      <Association Name="baseContent_tThread" Member="tThread" ThisKey="Id" OtherKey="ContentId" Type="tThread" Cardinality="One" />
      <Association Name="baseContent_tThread1" Member="RelatedThreads" Storage="_RelatedThread" ThisKey="Id" OtherKey="RelatedContentId" Type="tThread" />
      <Association Name="baseContent_ContentVisit" Member="ContentVisit" Storage="_ContentVisits" ThisKey="Id" OtherKey="ContentId" Type="ContentVisit" Cardinality="One" />
      <Association Name="baseContent_tThreadAnswer" Member="tThreadAnswer" ThisKey="Id" OtherKey="ContentId" Type="tThreadAnswer" Cardinality="One" />
      <Type Name="baseRole" Id="ID51" InheritanceCode="2" />
      <Type Name="baseFolder" Id="ID52" InheritanceCode="3" />
      <Type Name="TopicContent" Id="ID53" InheritanceCode="5" />
      <Type Name="TopicPageContent" Id="ID54" InheritanceCode="6" />
      <Type Name="baseDictionaryContent" Id="ID55" InheritanceCode="7" />
      <Type Name="FileContent" Id="ID56" InheritanceCode="8" />
      <Type Name="TopicPlaceholderContent" Id="ID57" InheritanceCode="9" />
      <Type Name="TopicModuleContent" Id="ID58" InheritanceCode="10" />
      <Type Name="TopicLinkContent" Id="ID59" InheritanceCode="11" />
      <Type Name="TopicPageLayoutContent" Id="ID60" InheritanceCode="12" />
      <Type Name="TopicThemeContent" Id="ID61" InheritanceCode="13" />
      <Type Name="TopicNewsContent" Id="ID62" InheritanceCode="14" />
      <Type Name="TopicMessageContent" Id="ID63" InheritanceCode="15" />
      <Type Name="TopicOfferContent" Id="ID64" InheritanceCode="16" />
      <Type Name="TopicVoteUpContent" Id="ID65" InheritanceCode="17" />
      <Type Name="TopicVoteDownContent" Id="ID66" InheritanceCode="18" />
      <Type Name="TopicOwnerContent" Id="ID67" InheritanceCode="19" />
      <Type Name="TopicModuleTypeContent" Id="ID68" InheritanceCode="20" />
      <Type Name="TopicContainerTypeContent" Id="ID69" InheritanceCode="21" />
      <Type Name="TopicLanguageContent" Id="ID70" InheritanceCode="22" />
      <Type Name="TopicGoodieContent" Id="ID71" InheritanceCode="23" />
      <Type Name="TopicModuleSkinContent" Id="ID72" InheritanceCode="24" />
      <Type Name="TopicEventContent" Id="ID73" InheritanceCode="25" />
      <Type Name="TopicLocationContent" Id="ID74" InheritanceCode="26" />
      <Type Name="AbstractContentItem" Id="ID75" InheritanceCode="10000" />
      <Type Name="TopicThreadContent" Id="ID76" InheritanceCode="27" />
      <Type Name="TopicThreadAnswerContent" Id="ID77" InheritanceCode="28" />
      <Type Name="NavigationInfoContent" Id="ID78" InheritanceCode="29" />
      <Type Name="TopicViewContent" Id="ID79" InheritanceCode="30" />
      <Type Name="VisitedContent" Id="ID80" InheritanceCode="31" />
    </Type>
  </Table>

Here is declaration for SP:

<Function Name="dbo.SearchAdvanced" Method="SearchAdvanced">
    <Parameter Name="searchTerm" Type="System.String" DbType="NVarChar(4000)" />
    <Parameter Name="searchKeywords" Type="System.String" DbType="NVarChar(4000)" />
    <Parameter Name="searchType" Type="System.Int64" DbType="BigInt" />
    <Parameter Name="searchTreeType" Type="System.Int64" DbType="BigInt" />
    <Parameter Name="parentList" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="filterList" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="filterValue" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="filterLessList" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="filterLessValue" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="filterGreaterList" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="filterGreaterValue" Type="System.String" DbType="VarChar(MAX)" />
    <Parameter Name="LCID" Parameter="lCID" Type="System.Int32" DbType="Int" />
    <Parameter Name="minLevels" Type="System.Int32" DbType="Int" />
    <Parameter Name="Levels" Parameter="levels" Type="System.Int32" DbType="Int" />
    <Parameter Name="pageSize" Type="System.Int32" DbType="Int" />
    <Parameter Name="PageNumber" Parameter="pageNumber" Type="System.Int32" DbType="Int" />
    <Parameter Name="sortOrder" Type="System.Int32" DbType="Int" />
    <Parameter Name="TopicContentId" Parameter="topicContentId" Type="System.Int64" DbType="BigInt" />
    <Parameter Name="totalRows" Type="System.Int32" DbType="Int" Direction="InOut" />
    <ElementType IdRef="ID50" />
  </Function>
问题回答

Would it be possible to re-test with the VS2010 beta? There is, IIRC, a bug with one of the IQueryable<T> implementations re base-classes that is fixed in 4.0. You might find it works in 4.0, and then the question becomes: wait until April?

Just use standard fault finding techniques - halve and check

Edit SP to only have first half of paramters, adjust mapping to same. No problem - try other half. Still have problem, halve again unti you find what is causing it





相关问题
Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

C++ Class Inheritance problem

Hi I have two classes, one called Instruction, one called LDI which inherits from instruction class. class Instruction{ protected: string name; int value; public: Instruction(string ...

Overloading a method in a subclass in C++

Suppose I have some code like this: class Base { public: virtual int Foo(int) = 0; }; class Derived : public Base { public: int Foo(int); virtual double Foo(double) = 0; }; ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn t let me pass arguments to functions through event listeners, which makes me feel sad,...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual ...

热门标签