{"id":8517,"date":"2023-02-27T09:59:42","date_gmt":"2023-02-27T00:59:42","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=8517"},"modified":"2023-03-06T18:45:18","modified_gmt":"2023-03-06T09:45:18","slug":"memory-cache-3-tables-tablemappings-and-linq-query","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=8517","title":{"rendered":"Memory Cache (3 tables TableMappings)"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Overview:  DataSet TableMappings\uc744  \uc774\uc6a9\ud558\uc5ec \uad00\uacc4\ud615\uc73c\ub85c Table 3\uac1c\ub97c \uce90\uc2f1\ud574\ubcf8\ub2e4.<\/h3>\n\n\n\n<h2 class=\"wp-block-heading\">1.Net Framework 4.6 \uc774\uc0c1\uc5d0\uc11c \uc124\uce58\uac00\ub2a5<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9.png\"><img loading=\"lazy\" decoding=\"async\" width=\"910\" height=\"577\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9.png\" alt=\"\" class=\"wp-image-8234\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9.png 910w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9-300x190.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9-768x487.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-9-660x418.png 660w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2.\uc124\uce58<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">NuGet \ud328\uce90\uc9c0 \uad00\ub9ac\uc5d0\uc11c \uc124\uce58 \ubc0f \ucc38\uc870 \ucd94\uac00 \ud655\uc778<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"602\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8.png\" alt=\"\" class=\"wp-image-8233\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8.png 902w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8-300x200.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8-768x513.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-8-660x440.png 660w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3.\ucc38\uc870 \ud655\uc778<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11.png\"><img loading=\"lazy\" decoding=\"async\" width=\"327\" height=\"531\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11.png\" alt=\"\" class=\"wp-image-8243\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11.png 327w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/01\/image-11-185x300.png 185w\" sizes=\"auto, (max-width: 327px) 100vw, 327px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Simple Source<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" title=\"System.Runtime.Caching.MemoryCache\">using (SqlConnection conn = new SqlConnection(connectionString))\n                    {\n                        conn.Open();\n                        SqlCommand com = new SqlCommand();\n                        SqlDataAdapter da = new SqlDataAdapter(\n                            \"SELECT [Account_ID]\" +\n                                  \",[Account_Number]\" +\n                                  \",[Balance]\" +\n                                  \"  FROM [Bank].[dbo].[Account];\" +\n                            \"SELECT [IDX]\" +\n                                  \",[Account_ID]\" +\n                                  \",[Name]\" +\n                                  \",[Mobile]\" +\n                                  \",[Regi_Date]\" +\n                                  \"  FROM [Bank].[dbo].[CustomerDetails];\" +\n                             \"SELECT [IDX]\" +\n                                  \",[Account_ID]\" +\n                                  \",[Amount]\" +\n                                  \",[New_Balance]\" +\n                                  \",[Transaction_Date]\" +\n                                  \"  FROM [Bank].[dbo].[Transaction];\"\n                                  , conn);\n                        \/\/ Add table mappings.\n                        \/\/da.SelectCommand.Parameters.AddWithValue(\"@year\", 2002);\n                        da.TableMappings.Add(\"Table\", \"Account\");\n                        da.TableMappings.Add(\"Table1\", \"CustomerDetails\");\n                        da.TableMappings.Add(\"Table2\", \"Transaction\");\n                        da.Fill(ds);\n                        DataTable account = ds.Tables[\"Account\"];\n                        DataTable customerdetails = ds.Tables[\"CustomerDetails\"];\n                        DataTable transaction = ds.Tables[\"Transaction\"];\n                        DataRelation relation1 = new DataRelation(\"AccountCustomerDetails\",\n                                                    account.Columns[\"Account_ID\"],\n                                                    customerdetails.Columns[\"Account_ID\"], true);\n                        DataRelation relation2 = new DataRelation(\"CustomerDetailsTransaction\",\n                                                    customerdetails.Columns[\"Account_ID\"],\n                                                    transaction.Columns[\"Account_ID\"], true);\n                        ds.Relations.Add(relation1);\n                        ds.Relations.Add(relation2);\n                    }<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Process diagram<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32.png\"><img loading=\"lazy\" decoding=\"async\" width=\"633\" height=\"696\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32.png\" alt=\"\" class=\"wp-image-8480\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32.png 633w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-32-273x300.png 273w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">6.DB<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33.png\"><img loading=\"lazy\" decoding=\"async\" width=\"599\" height=\"490\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33.png\" alt=\"\" class=\"wp-image-8481\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33.png 599w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-33-300x245.png 300w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">7.WebService Call (DataSet)<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"488\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-1024x488.png\" alt=\"\" class=\"wp-image-8483\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-1024x488.png 1024w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-300x143.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-768x366.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34-660x314.png 660w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-34.png 1403w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">using System.Web.Services;\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Collections.Generic;\nusing System.Linq;\n \nnamespace WebService1\n{   \n    public class Service1 : System.Web.Services.WebService\n    {\n \n        [WebMethod()]\n        public DataSet GetProductCatalog()\n        {\n            \/\/ Return the complete DataSet (from the cache, if possible).         \n            \/\/return Function.GetCache();\n            return CacheClass.GetCustomerDataSet();\n        }\n \n [WebMethod()]\n        public string[] GetProductList()\n        {\n            \/\/ Get the customer table (from the cache if possible).         \n            DataSet ds = CacheClass.GetCustomerDataSet();\n            IEnumerable&lt;DataRow&gt; result = (from Account in ds.Tables[\"Account\"].AsEnumerable()\n                                           join Transaction in ds.Tables[\"Transaction\"].AsEnumerable()\n                                           on new { Account_ID = Account[\"Account_ID\"] } equals new { Account_ID = Transaction[\"Account_ID\"] }\n                                           where Account.Field&lt;int&gt;(\"Account_ID\") == 1\n                                           select Account);\n            \/\/ Create an array that will hold the name of each customer.         \n            string[] names = new string[result.Count()];\n            \/\/ Fill the array.         \n            int i = 0;\n            foreach (DataRow row in result)\n            {\n                names[i] = row[\"Account_Number\"].ToString();\n                i += 1;\n            }\n            return names;\n        }\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">8.Cache Insert (DataSet)<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">using System;\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Runtime.Caching;\nnamespace WebService1\n{\n    public class CacheClass\n    {\n        private static string _key = \"Customers\";\n        private static readonly MemoryCache _cache = MemoryCache.Default;\n        \/\/private static string connectionString = \"Data Source=localhost;\" + \"Initial Catalog=Northwind;user ID=sa\";\n        private static string connectionString = \"Server=SQLOLEDB.1;Password=*******;Persist Security Info=True;User ID=MYID;Initial Catalog=MYDB;Data Source=MYCOM\";\n        public static DataSet GetCustomerDataSet()\n        {\n             if (!(_cache.Get(_key) is DataSet ds))\n            {\n                ds = new DataSet();\n                \/\/ Execute the command.             \n                try\n                {\n                    using (SqlConnection conn = new SqlConnection(connectionString))\n                    {\n                        string SQL = \"SELECT Account_ID, Account_Number, Balance FROM [Bank].[dbo].[Account]\";\n                        SqlCommand com = new SqlCommand(SQL, conn);\n                        SqlDataAdapter adapter = new SqlDataAdapter(com);\n                        conn.Open();\n                        adapter.Fill(ds, \"Account\");\n                        \/\/\/\/\n                        SQL = \"SELECT IDX, Account_ID, Amount, New_Balance, Transaction_Date FROM [Bank].[dbo].[Transaction]\";\n                        com = new SqlCommand(SQL, conn);\n                        adapter = new SqlDataAdapter(com);\n                        adapter.Fill(ds, \"Transaction\");\n                        \/\/\/\n                        SQL = \"SELECT IDX,Account_ID,Name,Mobile,Regi_Date FROM [Bank].[dbo].[CustomerDetails]\";\n                        com = new SqlCommand(SQL, conn);\n                        adapter = new SqlDataAdapter(com);\n                        adapter.Fill(ds, \"CustomerDetails\");\n                        DataRelation relation = ds.Relations.Add(\"Relation\",\n                          ds.Tables[\"Account\"].Columns[\"Account_ID\"],\n                          ds.Tables[\"Transaction\"].Columns[\"Account_ID\"]);\n                        DataRelation relation2 = ds.Relations.Add(\"Relation2\",\n                          ds.Tables[\"Account\"].Columns[\"Account_ID\"],\n                          ds.Tables[\"CustomerDetails\"].Columns[\"Account_ID\"]);\n                        \/\/conn.Close();\n                        \/\/conn.Dispose();\n                    }\n                    var cacheItemPolicy = new CacheItemPolicy()\n                    {\n                        \/\/Set your Cache expiration.\n                        AbsoluteExpiration = DateTime.Now.AddMinutes(60)\n                    };\n                    _cache.Add(_key, ds, cacheItemPolicy);\n                }\n                catch (Exception err)\n                {\n                    System.Diagnostics.Debug.WriteLine(err.ToString());\n                }\n            }\n            return _cache.Get(_key) as DataSet;\n        }\n    }\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">9.\ub514\ubc84\uadf8 ds<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29.png\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"342\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29.png\" alt=\"\" class=\"wp-image-8464\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29.png 820w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29-300x125.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29-768x320.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-29-660x275.png 660w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">10.\ud654\uba74<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-35.png\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"643\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-35.png\" alt=\"\" class=\"wp-image-8518\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-35.png 786w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-35-300x245.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-35-768x628.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">11.Result<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-36.png\"><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"717\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-36.png\" alt=\"\" class=\"wp-image-8519\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-36.png 862w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-36-300x250.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2023\/02\/image-36-768x639.png 768w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.tenor.com\/B-TP3rs3l7IAAAAC\/memory-cant-remember.gif\" alt=\"\" class=\"wp-image--953812295\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Overview: DataSet TableMappings\uc744 \uc774\uc6a9\ud558\uc5ec \uad00\uacc4\ud615\uc73c\ub85c Table 3\uac1c\ub97c \uce90\uc2f1\ud574\ubcf8\ub2e4. 1.Net Framework 4.6 \uc774\uc0c1\uc5d0\uc11c \uc124\uce58\uac00\ub2a5 2.\uc124\uce58 NuGet \ud328\uce90\uc9c0 \uad00\ub9ac\uc5d0\uc11c \uc124\uce58 \ubc0f \ucc38\uc870 \ucd94\uac00 \ud655\uc778 3.\ucc38\uc870 \ud655\uc778 4. <a class=\"mh-excerpt-more\" href=\"https:\/\/www.auctionpro.co.kr\/?p=8517\" title=\"Memory Cache (3 tables TableMappings)\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[237],"tags":[],"class_list":["post-8517","post","type-post","status-publish","format-standard","hentry","category-memory-cache"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8517"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8517\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}