我遵循的是从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]
答案 0 :(得分:0)
您已经将表格设置为使用[DynamoDBTable("BuildingRoutes")]
属性进行扫描。之所以出现错误,是因为您随后尝试扫描表中没有“ BuildingRoutes”属性的“ BuildingRoutes”属性。
简而言之,只需删除以下行:
new ScanCondition("BuildingRoutes", ScanOperator.Equal, tableName)
(您的tableName参数也是不必要的!)