コード例 #1
0
        public static ToolModelIdValue SelectResult(this EFModel model)
        {
            object[] attrs = model.GetType().GetCustomAttributes(typeof(DisplaybleAttribute), true);
            var      prop  = (attrs[0] as DisplaybleAttribute).Displayble;

            return(new ToolModelIdValue
            {
                Id = model.Id.ToString(),
                Value = model.GetType().GetProperty(prop).GetValue(model).ToString()
            });
        }
コード例 #2
0
        protected void BaseCascadeInsert(EFModel model)
        {
            var type = model.GetType();

            foreach (var property in type.GetProperties())
            {
                if (property.GetCustomAttribute <DeepTrackingPropertyAttribute>() != null)
                {
                    if (property.GetValue(model) is EFModel subModel)
                    {
                        BaseCascadeInsert(subModel);
                    }
                }
                else if (property.GetCustomAttribute <DeepTrackingCollectionAttribute>() != null)
                {
                    if (property.GetValue(model) is IEnumerable <EFModel> enumerable)
                    {
                        foreach (var item in enumerable.ToList())
                        {
                            BaseCascadeInsert(item);
                        }
                    }
                }
            }
            type.GetProperty("ModUser")?.SetValue(model, Client.ModUser);
            type.GetProperty("ModComp")?.SetValue(model, Client.ModComp);
            DataContext.Entry(model).State = Microsoft.EntityFrameworkCore.EntityState.Added;
        }