public static void One_Child_TablePerHierarchy_SanityCheck(bool applyColumnType)
        {
            var options = new DbContextOptionsBuilder()
                          .UseSqlServer($"Data Source=(local);Initial Catalog=Test_{nameof(ProgramOneChildTphSanityCheck)}_{applyColumnType};Integrated Security=SSPI;").Options;

            using (var db = new TestContext(options, applyColumnType))
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                // TODO write save logic
                var goodChild = new GoodChild()
                {
                    GoodChildData = Random30Characters()
                };

                db.Add(goodChild);

                var badChild = new BadChild()
                {
                };

                db.Add(badChild);

                db.SaveChanges();
            }
        }
示例#2
0
        public static void One_TablePerHierarchy_To_One_TablePerHierarchy_Different_Discriminator_Names_With_Identity_Insert()
        {
            var options = new DbContextOptionsBuilder()
                          .UseSqlServer($"Data Source=(local);Initial Catalog=Test_{nameof(ProgramOneTphToOneTphDifferentDiscriminatorNamesWithIdentityInsert)};Integrated Security=SSPI;").Options;

            using (var db = new TestContext(options))
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                // TODO write save logic
                var goodChild = new GoodChild()
                {
                    Parent           = new GoodParent()
                    {
                    }, GoodChildData = Random30Characters()
                };

                db.Add(goodChild);

                var badChild = new BadChild()
                {
                    Parent          = new BadParent()
                    {
                    }, BadChildData = Random30Characters()
                };

                db.Add(badChild);

                var goodParent = new GoodParent()
                {
                    Child = new GoodChild()
                    {
                        GoodChildData = Random30Characters()
                    },
                    GoodParentData = Random30Characters()
                };

                db.Add(goodParent);

                var badParent = new BadParent()
                {
                    Child = new BadChild()
                    {
                        BadChildData = Random30Characters()
                    },
                    BadParentData = Random30Characters()
                };

                db.Add(badParent);

                db.SaveChanges();
            }
        }
        protected void BindData(int goodChildID)
        {
            Func <GoodChild, bool> delegation = goodChild => goodChild.GoodChildID == goodChildID;
            var list = goodBLL.GetGoodChild(delegation);

            goodChild       = list.First();
            goodChild.Image = ConfigurationManager.AppSettings["UploadUrl"] + goodChild.Image;

            DetailsView1.DataSource = list;
            DetailsView1.DataBind();
            CurrentMode_Init();
        }
        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            try
            {
                var goodChild = new GoodChild();
                var file_url  = (HtmlInputHidden)DetailsView1.FindControl("file_url");
                if (!string.IsNullOrEmpty(file_url.Value))
                {
                    var img_url = (HtmlImage)DetailsView1.FindControl("img_url");
                    img_url.Src     = ConfigurationManager.AppSettings["UploadUrl"] + file_url.Value;
                    goodChild.Image = file_url.Value;
                }

                if (string.IsNullOrEmpty(file_url.Value))
                {
                    throw new Exception("图片不能为空");
                }

                if (e.Values["Specification"] == null)
                {
                    throw new Exception("规格不能为空");
                }

                if (e.Values["SalesVolume"] != null)
                {
                    goodChild.SalesVolume = Convert.ToInt32(e.Values["SalesVolume"].ToString());
                }
                if (e.Values["OrderBy"] != null)
                {
                    goodChild.OrderBy = Convert.ToInt32(e.Values["OrderBy"].ToString());
                }
                goodChild.Repertory     = Convert.ToInt32(e.Values["Repertory"].ToString());
                goodChild.Specification = e.Values["Specification"].ToString();
                goodChild.AddPrice      = Convert.ToDecimal(e.Values["AddPrice"].ToString());
                var CheckBoxList_State = ((CheckBoxList)DetailsView1.FindControl("CheckBoxList_State"));
                goodChild.State = 0;
                foreach (ListItem item in CheckBoxList_State.Items)
                {
                    if (item.Selected)
                    {
                        goodChild.State = goodChild.State | Convert.ToInt32(item.Value);
                    }
                }


                goodChild.CreateTime = DateTime.Now;
                goodChild.UpdateTime = DateTime.Now;
                using (Entity entity = new Entity())
                {
                    entity.GoodChild.Add(goodChild);
                    goodChild.GoodId = Convert.ToInt32(ViewState["goodID"]);
                    var good = entity.Good.Find(goodChild.GoodId);
                    goodChild.GoodGategoryID = good.GoodGategoryID;
                    entity.SaveChanges();
                }
                Response.Redirect("GoodChildDetail.aspx?goodChildID=" + goodChild.GoodChildID + "&goodID=" + goodChild.GoodId);
            }
            catch (Exception exception)
            {
                string error = exception.GetErrorMessage().Replace("'", "\\'").Replace("\"", "\\\"").Replace("\r\n", "\\r\\n");
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", string.Format("<script>alert('{0}')</script>", error));
            }
        }