コード例 #1
0
        private void LoadTestData()
        {
            List <User> tempList = new List <User>();

            // Extract test data from XDoc and store in List<>
            IEnumerable <XElement> users =
                from user in xmlDocument.Elements("Users").Elements("User")
                select user;

            // Convert XElement List<> into User List<>
            foreach (XElement user in users)
            {
                if (user != null && user.Element("Id").Value != null)
                {
                    User   tempUser = new User();
                    string x        = user.Element("Id").Value;
                    if (int.TryParse(x, out int y))
                    {
                        tempUser.Id = y;
                    }

                    tempUser.Name = user.Element("Name").Value;
                    tempList.Add(tempUser);
                }
            }
            // Load User List<> into Test Database
            DataConfig.BulkDirectCreate(tempList);
        }