private static int Main(string[] args) { #if DEBUG LogManager.AddDebugListener(true); #endif var consoleLogListener = new OutputLogListener(); LogManager.AddListener(consoleLogListener); Uri remoteGitUrl = null; string commitId = null; string baseDir = null; string pdbPath = null; bool skipVerify = false; LinkMethod method = LinkMethod.Http; var arguments = ArgumentSyntax.Parse(args, syntax => { syntax.DefineOption("m|method", ref method, v => (LinkMethod)Enum.Parse(typeof(LinkMethod), v, true), "The method for SRCSRV to retrieve source code. One of <" + string.Join("|", Enum.GetNames(typeof(LinkMethod))) + ">. Default is " + method + "."); syntax.DefineOption("u|url", ref remoteGitUrl, s => new Uri(s, UriKind.Absolute), "Url to remote git repository."); syntax.DefineOption("commit", ref commitId, "The git ref to assume all the source code belongs to."); syntax.DefineOption("baseDir", ref baseDir, "The path to the root of the git repo."); syntax.DefineOption("s|skipVerify", ref skipVerify, "Verify all source files are available in source control."); syntax.DefineParameter("pdb", ref pdbPath, "The PDB to add source indexing to."); if (!string.IsNullOrEmpty(pdbPath) && !File.Exists(pdbPath)) { syntax.ReportError($"File not found: \"{pdbPath}\""); } if (!string.IsNullOrEmpty(baseDir) && !Directory.Exists(baseDir)) { syntax.ReportError($"Directory not found: \"{baseDir}\""); } }); if (string.IsNullOrEmpty(pdbPath)) { Log.Info(arguments.GetHelpText()); return(1); } var options = new LinkOptions { GitRemoteUrl = remoteGitUrl, GitWorkingDirectory = baseDir != null?Catel.IO.Path.GetFullPath(baseDir, Environment.CurrentDirectory) : null, CommitId = commitId, SkipVerify = skipVerify, Method = method, }; if (!Linker.Link(pdbPath, options)) { return(1); } WaitForKeyPressWhenDebugging(); return(0); }
//[TestMethod] public void TestAttach() { LinkMethod lm = null; using (MyDBExt db = new MyDBExt()) { lm = db.LinkMethods.Include(p => p.user).FirstOrDefault(); } User user = null; using (MyDBExt db = new MyDBExt()) { user = db.Users.FirstOrDefault(u => !u.Code.Equals(lm.user.ID)); } lm.MethodType = "B"; lm.user = user; using (MyDBExt db = new MyDBExt()) { // 附加到新上下文 // 方法一 //db.Entry(lm).State = System.Data.EntityState.Modified; //db.Entry<User>(lm.user).State = System.Data.EntityState.Modified; db.LinkMethods.Add(lm); // lm.user的状态也是Added,如果不把lm.user的状态设置为Unchanged,就会出现主键重复的错误 db.Entry <LinkMethod>(lm).State = System.Data.EntityState.Modified; //db.Entry<User>(lm.user).State = System.Data.EntityState.Unchanged; DbReferenceEntry dre = db.Entry <LinkMethod>(lm).Reference(l => l.user); bool x = dre.IsLoaded; User u = lm.user; x = dre.IsLoaded; DbEntityEntry <LinkMethod> dee = db.Entry <LinkMethod>(lm); DbPropertyEntry dpe = dee.Property(l => l.MethodType); //db.LinkMethods.Attach(lm); //lm.user = user; db.SaveChanges(); } using (MyDBExt db = new MyDBExt()) { IQueryable s = db.Users.Select(u => new { u, xX = db.LinkMethods.Where(l => l.user.ID.Equals(u.ID)).Count() }); // OK //IQueryable s = db.Users.Select(u => new { u, xX = db.LinkMethods.Where(l => l.user.ID.Equals(u.ID)).Select(l => l.MethodType) }); //NO //IQueryable s = db.Users.Select(u => new { u, xX = "ddddddddddddd" }); //OK } }
public void Translate(LinkMethod method) { var value = method switch { LinkMethod.And => " and", LinkMethod.Or => " or", LinkMethod.None => "", _ => throw new NotImplementedException() }; _builder.Append(value); } }
public void TestMethod1() { using (MyDBExt db = new MyDBExt()) { //db.Configuration.LazyLoadingEnabled = true; //DbSet<LinkMethod> lmss = db.Set<LinkMethod>(); //lmss.Create(); //IQueryable<LinkMethod> lmsOld = ext.Set(typeof(LinkMethod)); // 错误信息:实体类型LinkMethod不是当前上下文db的模型的一部分 Expression <Func <LinkMethod, LinkMethod> > d2 = p => p; IQueryable <LinkMethod> lmsOld = db.LinkMethods.Select(d2); // 单向关联,反向查询 // p.LinkMethods 等价于 db.LinkMethods.Where(l => l.user.ID.Equals(p.ID)) 或者 db.LinkMethods.Where(l => l.user == p) //IQueryable<User> test = db.Users.Where(p => db.LinkMethods.Where(l => l.user == p).Count() > 0); IQueryable test = db.Users.Select(p => db.LinkMethods.Where(l => l.user == p).Select(l => l)); IQueryable test1 = db.Users.Select(p => new { p.Name, p.Code, p.Roles }); //IQueryable<User> test = db.Users.Where(p => p.LinkMethods(db).Where(l => l.user == p).Count() > 0); //IQueryable test = db.Users.Select(p => p.Roles); //IQueryable<LinkMethod> lmsOld = lmss.Select(p => p); foreach (LinkMethod lm in lmsOld) { db.LinkMethods.Remove(lm); //db.Set<LinkMethod>().Remove(lm); } //ext.SaveChanges(); User userOld = db.Users.FirstOrDefault(p => p.Code.Equals("xiongxiong")); if (userOld != null) { db.Users.Remove(db.Users.FirstOrDefault(p => p.Code.Equals("xiongxiong"))); } User u = new User(); u.ID = Guid.NewGuid().ToString(); u.Code = "xiongxiong"; u.Name = "雄"; u.Password = "******"; db.Users.Add(u); LinkMethod lm1 = new LinkMethod(); lm1.ID = Guid.NewGuid().ToString(); lm1.MethodType = "A"; lm1.Content = "content"; lm1.user = u; db.LinkMethods.Add(lm1); //db.Set<LinkMethod>().Add(lm1); db.SaveChanges(); IQueryable <LinkMethod> lms = db.Set <LinkMethod>().Select(p => p); //IQueryable<User> users = ext.Users.Select(p => p); //ICollection<LinkMethod> lms1 = users.Select(p => p.getLinkMethodsByUser()); } }