gpt4 book ai didi

c# - 如何使用对 Azure 表存储的单个查询检索多种类型的实体?

转载 作者:太空狗 更新时间:2023-10-29 22:27:41 26 4
gpt4 key购买 nike

我试图了解 Azure 表存储如何创建 facebook 风格的提要,但我陷入了如何检索条目的困境。

(我的问题几乎与 https://stackoverflow.com/questions/6843689/retrieve-multiple-type-of-entities-from-azure-table-storage 相同,但答案中的链接已损坏。)

这是我想要的方法:

  1. 为我的应用程序中的所有用户创建个人源,其中可以包含不同类型的条目(通知、状态更新等)。我的想法是将它们存储在按每个用户的分区键分组的 Azure 表中。

  2. 检索同一分区键中的所有条目,并根据条目类型将其传递到不同的 View 。

How do I query the table storage for all types of the same base type while keeping their unique properties?

CloudTableQuery<TElement>如果我指定 EntryBase 则需要类型化实体作为通用参数,我没有获得特定于条目的属性( NotificationSpecificPropertyStatusUpdateSpecificProperty ),反之亦然。

我的实体:

public class EntryBase : TableServiceEntity
{
public EntryBase()
{


}
public EntryBase(string partitionKey, string rowKey)
{
this.PartitionKey = partitionKey;
this.RowKey = rowKey;
}
}


public class NotificationEntry : EntryBase
{
public string NotificationSpecificProperty { get; set; }
}

public class StatusUpdateEntry : EntryBase
{
public string StatusUpdateSpecificProperty { get; set; }
}

我的 Feed 查询:

List<AbstractFeedEntry> entries = // how do I fetch all entries?

foreach (var item in entries)
{

if(item.GetType() == typeof(NotificationEntry)){

// handle notification

}else if(item.GetType() == typeof(StatusUpdateEntry)){

// handle status update

}

}

最佳答案

终于有官方的办法了! :)

查看 Azure 存储团队博客链接中的 NoSQL 示例,该示例正是执行此操作:

Windows Azure Storage Client Library 2.0 Tables Deep Dive

关于c# - 如何使用对 Azure 表存储的单个查询检索多种类型的实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10697752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com