简体   繁体   中英

When does SPMetal generate EntityRef properties for lookup fields?

I have a defined a content type called SPVideoDataItem containing those two fields:

<Field ID="{487F2AD6-D9D6-47AA-AA99-B3FFF893E689}" Name="LUVideoQuality" Group="Custom Columns" Type="Lookup" DisplayName="Video Quality" List="Lists/GlobalVideoQualityList" ShowField="Title" PrependId="TRUE" ShowInEditForm="TRUE" ShowInNewForm="TRUE"/>
<Field ID="{F348A825-764D-41EE-AF92-8CF1DC246E47}" Name="LUVideoTitle" Group="Custom Columns" Type="Lookup" DisplayName="Video Title"  List="Lists/VideoItemList" ShowInEditForm="TRUE"  ShowInNewForm="TRUE" ShowField="VideoItemTitle" PrependId="TRUE" Required="TRUE"/>

For LUVideoQuality I get a property in a class called VideoItemDataListSPVideoDataItem :

public SPVideoQualityItem VideoQuality

which exposes a EntityRef-Member, so I can access all properties of SPVideoQualityItem.

However, for LUVideoTitle spmetal just generates two properties in the parent class SPVideoDataItem

public string VideoTitleVideoItemTitle
public System.Nullable<int> VideoTitleId 

where I can only access title and ID.

I wonder why spmetal handles this two lookups differently. Can anyone explain this behaviour? I would prefer that all lookups are handled like LUVideoQuality in my example.

I've encountered the same issue.

When I let go of the principle to create a separate content type and just created a list based on content type Item it did generate the entity refs.

Apparently it has something to do with the "WebId" property of the lookup fields. A colleague told me that they got it working by adding

WebId="~sitecollection" 

to all lookup fields in the content type definitions (Elements.xml). Im not marking this as an answer because I did not check if it is working now because of this attribute or some other change in the definitions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM