Exemplo n.º 1
0
        private void Write(AddAsyncMethod method)
        {
            WriteSignature(method);
            using (_builder.IndentBraced)
            {
                _("if (Entity == null)");

                using (_builder.IndentBraced)
                {
                    _("Context.AddObject(Path, item);");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var lastSlash = Path.LastIndexOf('/');");
                    _("var shortPath = (lastSlash >= 0 && lastSlash < Path.Length - 1) ? Path.Substring(lastSlash + 1) : Path;");
                    _("Context.AddRelatedObject(Entity, shortPath, item);");
                }

                _("if (!deferSaveChanges)");

                using (_builder.IndentBraced)
                {
                    _("return Context.SaveChangesAsync();");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var retVal = new global::System.Threading.Tasks.TaskCompletionSource<object>();");
                    _("retVal.SetResult(null);");
                    _("return retVal.Task;");
                }
            }
        }
Exemplo n.º 2
0
        private void Write(AddAsyncMethod method)
        {
            WriteSignature(method);
            using (_builder.IndentBraced)
            {
                _("if (Entity == null)");

                using (_builder.IndentBraced)
                {
                    _("Context.AddObject(Path, item);");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var lastSlash = Path.LastIndexOf('/');");
                    _("var shortPath = (lastSlash >= 0 && lastSlash < Path.Length - 1) ? Path.Substring(lastSlash + 1) : Path;");
                    _("Context.AddRelatedObject(Entity, shortPath, item);");
                }

                _("if (!deferSaveChanges)");

                using (_builder.IndentBraced)
                {
                    _("return Context.SaveChangesAsync();");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var retVal = new global::System.Threading.Tasks.TaskCompletionSource<object>();");
                    _("retVal.SetResult(null);");
                    _("return retVal.Task;");
                }
            }
        }