3

我创建了一个 asp.net core 2.0 Web 应用程序,您可以在其上查询 Partitionkey 和 2 个双字段(评级和温度)的 azure 表。使用 python 脚本在另一个进程中每天更新表存储 4 次。脚本偶尔会在表中写入一些空的双字段。不幸的是,表查询引发异常: “来自表服务的意外 EDM 类型:Edm.Double.来自表服务的意外 EDM 类型:Edm.Double。”

这是我用来查询表的代码:

 //filters
        string datefilter = (TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, date));
        string ratingfilter = (TableQuery.GenerateFilterConditionForDouble(RatingColumn, QueryComparisons.GreaterThanOrEqual, Rating));
        string tempfilter = (TableQuery.GenerateFilterConditionForDouble(TempColumn, QueryComparisons.GreaterThanOrEqual, Temp));

        //query
        TableQuery<RatingsEntity> query =
            new TableQuery<RatingsEntity>()
            .Where(TableQuery.CombineFilters(
                    TableQuery.CombineFilters(
                        datefilter, TableOperators.And, ratingfilter),
                                TableOperators.And, tempfilter) 
            );



        List<RatingsEntity> ratings = new List<RatingsEntity>();
        TableContinuationToken token = null;
        do
        {
            TableQuerySegment<RatingsEntity> resultSegment = await ratingTable.ExecuteQuerySegmentedAsync(query, token);
            token = resultSegment.ContinuationToken;

            foreach (RatingsEntity rating in resultSegment.Results)
            {
                ratings.Add(rating);
            }
        } while (token != null);

        if (ratings.Count == 0)
        {
            return View("~/Views/Home/NotFound.cshtml");
        }
        else ....

我的实体如下所示:

    public class RatingsEntity : TableEntity
{
    public RatingsEntity(string ratingdate, string latlon) {
        this.PartitionKey = ratingdate;
        this.RowKey = latlon;
    }

    public RatingsEntity() { }
    public double avgmaxtemp16 { get; set; }
    public double avgmaxtemp7 { get; set; }...

据我所知,在某些时候将查询结果映射到实体的过程会失败,因为类型不是双精度的,而是其他的,例如字符串。(存储资源管理器显示一个空的 double 类型)。我试图使双打可以为空,但没有成功。我查看了TableRequestOptions 类,它有一个 IsNull() 方法,但我不知道如何实现它,以及它是否可以工作。

4

0 回答 0