SPMetal 何时为查找字段生成 EntityRef 属性?
我定义了一个名为 SPVideoDataItem 的内容类型,其中包含这两个字段:
<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"/>
对于 LUVideoQuality,我在名为 VideoItemDataListSPVideoDataItem 的类中获得一个属性:
public SPVideoQualityItem VideoQuality
它公开了 EntityRef-Member,因此我可以访问 SPVideoQualityItem 的所有属性。
但是,对于 LUVideoTitle,spmetal 仅在父类 SPVideoDataItem 中生成两个属性
public string VideoTitleVideoItemTitle
public System.Nullable<int> VideoTitleId
,我只能访问标题和 ID。
我想知道为什么 spmetal 以不同的方式处理这两个查找。谁能解释这种行为?我希望所有查找都像我的示例中的 LUVideoQuality 一样处理。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题。
当我放弃创建单独的内容类型的原则并仅根据内容类型 Item 创建一个列表时,它确实生成了实体引用。
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.
显然它与查找字段的“WebId”属性有关。一位同事告诉我,他们通过添加
到内容类型定义 (Elements.xml) 中的所有查找字段来使其正常工作。我没有将其标记为答案,因为我没有检查它现在是否由于此属性或定义中的其他更改而工作。
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
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.