当前位置: 首页>>代码示例>>C#>>正文


C# Document.GetAttributeNames方法代码示例

本文整理汇总了C#中Amazon.DynamoDB.DocumentModel.Document.GetAttributeNames方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetAttributeNames方法的具体用法?C# Document.GetAttributeNames怎么用?C# Document.GetAttributeNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.DynamoDB.DocumentModel.Document的用法示例。


在下文中一共展示了Document.GetAttributeNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunDocumentModelSample

        public static void RunDocumentModelSample()
        {
            Console.WriteLine("Loading Businesses table");
            Table table = Table.LoadTable(client, "Businesses");

            Console.WriteLine("Creating and saving first item");
            Document chainStore2 = new Document();
            chainStore2["Name"] = "Big Sales Inc";
            chainStore2["Id"] = 2;
            chainStore2["Owner"] = "Big Sales Corp";
            chainStore2["Managers"] = new List<string> { "Samantha Jones", "Richard Frost" };
            chainStore2["FoundedDate"] = new DateTime(1980, 7, 4);
            chainStore2["Address"] = "123 Main Street, New York, New York";
            chainStore2["Employees"] = 46;
            chainStore2["State"] = "NY";
            table.PutItem(chainStore2);

            Console.WriteLine("Creating and saving first item");
            Document chainStore13 = new Document();
            chainStore13["Name"] = "Big Sales Inc";
            chainStore13["Id"] = 13;
            chainStore13["Owner"] = "Big Sales Corp";
            chainStore13["Managers"] = new List<string> { "Anil Garg", "Alex Short" };
            chainStore13["FoundedDate"] = new DateTime(1999, 3, 15);
            chainStore13["Address"] = "1999 West Ave, Chicago, Illinois";
            chainStore13["Employees"] = 54;
            chainStore13["State"] = "IL";
            table.PutItem(chainStore13);

            Console.WriteLine("Creating and saving second item");
            Document tinyDiner = new Document();
            tinyDiner["Name"] = "Tiny Map-themed Diner";
            tinyDiner["Id"] = 0;
            tinyDiner["Owner"] = "John Doe";
            tinyDiner["FoundedDate"] = new DateTime(1974, 12, 10);
            tinyDiner["Address"] = "800 Lincoln Ave, Seattle, Washington";
            tinyDiner["State"] = "WA";
            table.PutItem(tinyDiner);

            Console.WriteLine("Creating and saving third item");
            Document internetStore = new Document();
            internetStore["Name"] = "Best Online Store Ever";
            internetStore["Id"] = 0;
            internetStore["Owner"] = "Jane Doe";
            internetStore["FoundedDate"] = new DateTime(1994, 2, 19);
            internetStore["Employees"] = 5;
            internetStore["Url"] = "http://www.best-online-store-ever.fake";
            internetStore["Phone"] = "425-555-1234";
            table.PutItem(internetStore);

            Console.WriteLine("Loading item");
            Document doc1 = table.GetItem("Big Sales Inc", 2);
            Console.WriteLine("Attribute counts match (should be true): " +
                (chainStore2.GetAttributeNames().Count == doc1.GetAttributeNames().Count));

            Console.WriteLine("Loading item...");
            Document doc2 = table.GetItem("Best Online Store Ever", 0);
            Console.WriteLine("Attribute counts match (should be true): " +
                (chainStore2.GetAttributeNames().Count == doc1.GetAttributeNames().Count));
            Console.WriteLine("Change item: remove one attribute, add one, modify one attribute");
            doc2["Phone"] = null;
            doc2["Twitter"] = "best-online-store-ever";
            doc2["Employees"] = 4;
            Console.WriteLine("Updating item");
            table.UpdateItem(doc2);

            Console.WriteLine("Reloading item");
            doc2 = table.GetItem("Best Online Store Ever", 0);
            Console.WriteLine("Phone attribute present (should be false): " + doc2.Contains("Phone"));
            Console.WriteLine("Twitter attribute present (should be true): " + doc2.Contains("Twitter"));
            Console.WriteLine("Employees attribute equals 4: " + (doc2["Employees"].AsPrimitive().Value == "4"));

            Console.WriteLine("Loading nonexistent item");
            Document doc3 = table.GetItem("Big Sales Inc", 3);
            Console.WriteLine("Returned document == null (should be true): " + (doc3 == null));

            Search query;
            Console.WriteLine();
            Console.WriteLine("Querying for items (Equals)");
            query = table.Query("Big Sales Inc", new RangeFilter(QueryOperator.Equal, 2));
            List<Document> queryItems1 = query.GetRemaining();
            Console.WriteLine("Number of items returned (should be 1): " + queryItems1.Count);

            Console.WriteLine();
            Console.WriteLine("Querying for items (Between)");
            QueryOperationConfig queryConfig = new QueryOperationConfig
            {
                HashKey = "Big Sales Inc",
                Filter = new RangeFilter(QueryOperator.Between, 0, 15),
                Limit = 1
            };
            query = table.Query(queryConfig);
            int totalItems = 0;
            while (!query.IsDone)
            {
                Console.WriteLine("Retrieving next set (page) of items");
                List<Document> querySet = query.GetNextSet();
                Console.WriteLine("Number of items returned in set (should be 1, unless last set, which will be 0): " + querySet.Count);

                foreach (Document doc in querySet)
//.........这里部分代码省略.........
开发者ID:thecloudbook,项目名称:amazon,代码行数:101,代码来源:DocumentModelSample.cs


注:本文中的Amazon.DynamoDB.DocumentModel.Document.GetAttributeNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。