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


C# Models.SaveChanges方法代码示例

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


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

示例1: Collect

        private static void Collect(Models.Source source, IList<Models.UserSourceLink> userSourceLinks, DateTime collectTime, SourceContentType sourceContentType, Models.ICContext context, string response, List<SourceContentRegexGroup> groupRegexes)
        {
            var domain = source.Domain;
            var hrefhead = GetUrlHead(source.Url);
            var datetime = DateTime.Now.Date.AddMonths(-1);

            foreach (var regexGroup in groupRegexes)
            {
                if (regexGroup.linkRegex == null)
                {
                    continue;
                }

                var sourceDate = collectTime;
                var match = regexGroup.groupRegex.Match(response, 0);
                while (match.Success)
                {
                    var matchValue = regexGroup.decode ? System.Net.WebUtility.HtmlDecode(match.Value) : match.Value;
                    if (!regexGroup.IsNotMatchSourceRegexes(matchValue, regexGroup.containerRegexes))
                    {
                        if (regexGroup.dateRegex != null)
                        {
                            var dateMatch = regexGroup.dateRegex.Match(matchValue);
                            if (!dateMatch.Success)
                            {
                                match = match.NextMatch();
                                continue;
                            }

                            var year = Convert.ToInt32(dateMatch.Groups["year"].Value);
                            var month = Convert.ToInt32(dateMatch.Groups["month"].Value);
                            var day = Convert.ToInt32(dateMatch.Groups["day"].Value);
                            sourceDate = new DateTime(year, month, day);
                        }

                        var linkMatch = regexGroup.linkRegex.Match(matchValue);
                        if (linkMatch.Success)
                        {
                            if (linkMatch.Groups["url"].Success && linkMatch.Groups["content"].Success)// && !regexGroup.IsNotMatchSourceRegexes(linkValue, regexGroup.hrefRegexes))
                            {
                                var url = linkMatch.Groups["url"].Value;
                                url = url.Substring(1, url.Length - 2);
                                if (!url.StartsWith("http"))
                                {
                                    if (url.StartsWith("./"))
                                    {
                                        url = hrefhead.TrimEnd('/') + url.TrimStart('.');
                                    }
                                    else if (url.StartsWith("/"))
                                    {
                                        url = source.Domain + url.TrimStart('/');
                                    }
                                    else
                                    {
                                        url = hrefhead + url;
                                    }
                                }

                                var content = crlfRegex.Replace(linkMatch.Groups["content"].Value, "");
                                if (!regexGroup.IsNotMatchSourceRegexes(content, regexGroup.contentRegexes))
                                {
                                    content = System.Net.WebUtility.HtmlDecode(htmlRegex.Replace(dateRegex.Replace(content, ""), "")).Trim('·', ' ', '\t');   // remove date string
                                    var sourceContent = context.SourceContents.Where(p => p.SourceId == source.SourceId && p.Url == url).FirstOrDefault();
                                    if (sourceContent == null)
                                    {
                                        sourceContent = new Models.SourceContent
                                         {
                                             AddTime = collectTime,
                                             AddDate = collectTime.Date,
                                             AddHour = collectTime.Hour,
                                             SourceDate = sourceDate,
                                             Content = content,
                                             ContentType = (int)sourceContentType,
                                             SourceId = source.SourceId,
                                             Url = url,
                                         };

                                        if (sourceDate >= datetime)
                                        {
                                            foreach (var userSouceLink in userSourceLinks)
                                            {
                                                sourceContent.UserSourceContentLinks.Add(new Models.UserSourceContentLink
                                                {
                                                    UserId = userSouceLink.UserId
                                                });
                                            }
                                        }

                                        context.SourceContents.Add(sourceContent);
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }

                    match = match.NextMatch();
                }
            }
        }
开发者ID:hbicexp,项目名称:InformationCollection,代码行数:100,代码来源:SourceContentManager.cs

示例2: Seed


//.........这里部分代码省略.........
                LabourNum = 9802
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "业务",
                LabourNum = 9803
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "人事",
                LabourNum = 9804
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "计财",
                LabourNum = 9805
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "信息与技术保障",
                LabourNum = 9807
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "雷电预警防护",
                LabourNum = 9808
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "人工影响天气",
                LabourNum = 9809
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "后勤服务中心",
                LabourNum = 98010
            });
            context.LaboursInfos.Add(new LaboursInfo
            {
                LabourName = "科技服务",
                LabourNum = 98011
            });

            context.Permissions.Add(new Permission
            {
                PermissionName = "Add",
            });
            context.Permissions.Add(new Permission
            {
                PermissionName = "Dlete",
            });
            context.Permissions.Add(new Permission
            {
                PermissionName = "Update",
            });

            context.Roles.Add(new Role
            {
                RoleName = "OnlineExamAdmin",
            });

            //WebSecurity.InitializeDatabaseConnection("MemberShip_MS_ConnectionString", "UserProfile", "ID", "UserName", autoCreateTables: false);
            //DataSet myQuestionBankDS = new DataSet();
            //string strConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Projects\CSharp\OnlinExam\OnlinExam\UserProfile.xlsx" + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
            //using (OleDbConnection myConn = new OleDbConnection(strConnection))
            //{
            //    try
            //    {

            //        string strCom = "SELECT * FROM [UserProfile$]";
            //        myConn.Open();
            //        OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
            //        myCommand.Fill(myQuestionBankDS, "[UserProfile]");
            //        myConn.Close();
            //    }
            //    catch
            //    {
            //    }
            //}
            //try
            //{
            //    DataTable tmpdt = myQuestionBankDS.Tables[0];
            //    foreach (DataRow row in tmpdt.Rows)
            //    {
            //        RegisterModel model = new RegisterModel();
            //        model.UserName = row.ItemArray[0].ToString();
            //        model.RealName = row.ItemArray[1].ToString();
            //        model.Password = row.ItemArray[2].ToString();
            //        model.ConfirmPassword = row.ItemArray[3].ToString();
            //        model.LabourNum = Convert.ToInt32(row.ItemArray[4].ToString());
            //        model.UnitNum = Convert.ToInt32(row.ItemArray[5].ToString());
            //        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { RealName = model.RealName, UnitNum = model.UnitNum, LabourNum = model.LabourNum, pword = model.Password }, false);
            //    }
            //}
            //catch
            //{
            //}

            context.SaveChanges();
        }
开发者ID:MadIHI,项目名称:InfoManage,代码行数:101,代码来源:MemberShip_seed.cs


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