【问题标题】:Unable to find storage information for property [TableName]找不到属性 [TableName] 的存储信息
【发布时间】:2019-09-12 05:34:10
【问题描述】:

我正在遵循我所理解的从 DynamoDB 数据库中提取对象映射的正确方法。我的问题是,当我执行 DyanmoDBContext.Scan 函数时,它会引发以下异常(如下所示)

抛出异常:AWSSDK.DynamoDBv2.dll 中的“System.InvalidOperationException”

显示为

无法找到属性 [BuildingRoutes] 的存储信息

我无法理解是什么导致了引发此异常,因此实际上并未转换为我的自定义类。

下面是主要功能。

class Program
{


    static void Main(string[] args)
    {

        // Initialize the Amazon Cognito credentials provider
        CognitoAWSCredentials credentials = new CognitoAWSCredentials(
            //Not showing my credentials for AWS.
        );



        var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
        DynamoDBContext context = new DynamoDBContext(client);


        try
        {
            // Query a specific forum and thread.
            string tableName = "BuildingRoutes";
            string primaryKey = "Witmer Hall";

            LowLevelQuery.Scan(tableName, primaryKey);

            List<RoomsObject> building = new List<RoomsObject>();

            Console.WriteLine("\n");

            IEnumerable<BuildingRoutes> BuildingRoutess = LowLevelQuery.contextScan(tableName, primaryKey);



            printBuilding(building);






            Console.WriteLine("Example complete. To continue, press Enter");
            Console.ReadLine();
        }
        catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); Console.ReadLine(); }
        catch (AmazonServiceException e) { Console.WriteLine(e.Message); Console.ReadLine(); }
        catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); }
    }

下面是我用来扫描数据库的自定义类。

 class DatabaseScan
{

    private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();

    public static void Scan(String tableName, String buildingName)
    {


        Table ThreadTable = Table.LoadTable(client, tableName);

        ScanFilter scanFilter = new ScanFilter();
        scanFilter.AddCondition("Building", ScanOperator.Equal, buildingName);

        Search search = ThreadTable.Scan(scanFilter);

        List<Document> documentList = new List<Document>();
        do
        {
            documentList = search.GetNextSet();
            Console.WriteLine("\nBelow are all the Edges that are returned from the scan.");
            foreach (var document in documentList)
                PrintDocument(document);
        } while (!search.IsDone);
    }

    public static IEnumerable<BuildingRoutes> contextScan(String tableName, String buildingName)
    {
        DynamoDBContext context = new DynamoDBContext(client);
        IEnumerable<BuildingRoutes> BuildingRoutess = context.Scan<BuildingRoutes>(
            new ScanCondition("Building", ScanOperator.Equal, buildingName),
            new ScanCondition("BuildingRoutes", ScanOperator.Equal, tableName)
            );

        return BuildingRoutess;

    }


}

最后一段代码是我试图转换和加载扫描数据的类

    [DynamoDBTable("BuildingRoutes")]
public class BuildingRoutes
{

    [DynamoDBHashKey("EdgeNum")]
    public int EdgeNum { get; set; }

    [DynamoDBProperty("Building")]
    public String Building { get; set; }

    [DynamoDBProperty("Destination")]
    public int Destination { get; set; }

    [DynamoDBProperty("Distance")]
    public int Distance { get; set; }

    [DynamoDBProperty("Origin")]
    public int Origin { get; set; }

    [DynamoDBProperty("OriginEntrance")]
    public Boolean OriginEntrance { get; set; }

    [DynamoDBProperty("DestinationEntrance")]
    public Boolean DestinationEntrance { get; set; }

    [DynamoDBProperty("MaxRangeLatitude")]
    public float MaxRangeLatitude { get; set; }

    [DynamoDBProperty("MaxRangeLongitude")]
    public float MaxRangeLongitude { get; set; }

    [DynamoDBProperty("MinRangeLatitude")]
    public float MinRangeLatitude { get; set; }

    [DynamoDBProperty("MinRangelongitude")]
    public float MinRangelongitude { get; set; }


}

最后一段文本是我用于文本的示例输出,让你们了解我要存储的信息。

Below are all the Edges that are returned from the scan.

MaxRangeLatitude - 13.525263
EdgeNum - 2
MaxRangeLongitude - 13.256354
MinRangeLongitude - 13.253648
DestinationEntrance -
Origin - 102
MinRangeLatitude - 13.526
Destination - 103
Building - Witmer Hall
OriginEntrance -

MaxRangeLatitude - 0
EdgeNum - 1
MaxRangeLongitude - 0
MinRangeLongitude - 0
DestinationEntrance -
Origin - 101
MinRangeLatitude - 0
Destination - 102
Building - Witmer Hall
OriginEntrance -

MaxRangeLatitude - 13.525263
EdgeNum - 0
MaxRangeLongitude - 13.256354
MinRangeLongitude - 13.253648
DestinationEntrance -
Origin - 0
MinRangeLatitude - 13.526
Destination - 101
Building - Witmer Hall
OriginEntrance -


Unable to find storage information for property [BuildingRoutes]

【问题讨论】:

    标签: c# amazon-dynamodb object-object-mapping


    【解决方案1】:

    您已经将表设置为使用[DynamoDBTable("BuildingRoutes")] 属性进行扫描。您会收到错误消息,因为您随后尝试扫描表中没有 BuildingRoutes 属性的属性“BuildingRoutes”。

    简而言之,只需删除以下行:

    new ScanCondition("BuildingRoutes", ScanOperator.Equal, tableName)
    

    (你的tableName参数也不需要!)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-14
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多