为什么我在查询 TableServiceContext 时收到 MissingMethodException?

发布于 2024-11-30 06:41:33 字数 1846 浏览 1 评论 0原文

我正在尝试查询 Azure 表存储。为此,我使用以下两种方法:

TableServiceContext:

public IQueryable<T> QueryEntities<T>(string tableName) where T : TableServiceEntity
{
    this.ResolveType = (unused) => typeof(T);
    return this.CreateQuery<T>(tableName);
}

使用上述方法的代码:

CloudStorageAccount account = AzureConnector.GetCloudStorageAccount(AppSettingsVariables.TableStorageConnection);

AzureTableStorageContext context = new AzureTableStorageContext(account.TableEndpoint.ToString(), account.Credentials);

// Checks if the setting already exists in the Azure table storage. Returns null if not exists.
var existsQuery = from e in context.QueryEntities<ServiceSettingEntity>(TableName)
                  where e.ServiceName.Equals(this.ServiceName) && e.SettingName.Equals(settingName)
                  select e;

ServiceSettingEntity existingSettginEntity = existsQuery.FirstOrDefault();

上面的 LINQ 查询生成以下请求 url:

http://127.0.0.1:10002/devstoreaccount1/PublicSpaceNotificationSettingsTable()?$filter=(ServiceName eq 'PublicSpaceNotification') and (SettingName eq 'expectiss')

类中的代码生成以下 MissingMethodException:

在此处输入图像描述

但我无法让它发挥作用。

I am trying to query a Azure Table Storage. For that I use the following two methods:

TableServiceContext:

public IQueryable<T> QueryEntities<T>(string tableName) where T : TableServiceEntity
{
    this.ResolveType = (unused) => typeof(T);
    return this.CreateQuery<T>(tableName);
}

Code that uses the method above:

CloudStorageAccount account = AzureConnector.GetCloudStorageAccount(AppSettingsVariables.TableStorageConnection);

AzureTableStorageContext context = new AzureTableStorageContext(account.TableEndpoint.ToString(), account.Credentials);

// Checks if the setting already exists in the Azure table storage. Returns null if not exists.
var existsQuery = from e in context.QueryEntities<ServiceSettingEntity>(TableName)
                  where e.ServiceName.Equals(this.ServiceName) && e.SettingName.Equals(settingName)
                  select e;

ServiceSettingEntity existingSettginEntity = existsQuery.FirstOrDefault();

The LINQ query above generates the following request url:

http://127.0.0.1:10002/devstoreaccount1/PublicSpaceNotificationSettingsTable()?$filter=(ServiceName eq 'PublicSpaceNotification') and (SettingName eq 'expectiss')

The code in the class generates the following MissingMethodException:

enter image description here

  • I have looked at the supported LINQ Queries for the Table API;
  • Looked at several working stackoverflow solutions;
  • Tried IgnoreResourceNotFoundException on the TableServiceContext (usercomments of QueryOperators);
  • Tried to convert the linq query with ToList() before calling first or default (usercomments of QueryOperators).

but I can't get this to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-12-07 06:41:33

确保您有“ServerSettingEntity”类的无参数构造函数。继承TableServiceEntity的“DTO”需要一个不带参数的构造函数。

Make sure you have parameterless constructor for the class "ServerSettingEntity". The ‘DTO’ that inherits TableServiceEntity needs a constructor with no parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文