Beispiel #1
0
            /// <summary>
            /// Ensure exists
            /// </summary>
            public override TModel InsertInternal(DataContext context, TModel data)
            {
                foreach (var rp in typeof(TModel).GetRuntimeProperties().Where(o => typeof(IdentifiedData).GetTypeInfo().IsAssignableFrom(o.PropertyType.GetTypeInfo())))
                {
                    if (rp.GetCustomAttribute<DataIgnoreAttribute>() != null || !rp.CanRead || !rp.CanWrite)
                        continue;

                    var instance = rp.GetValue(data);
                    if (instance != null)
                        rp.SetValue(data, DataModelExtensions.EnsureExists(instance as IdentifiedData, context));
                }
                return base.InsertInternal(context, data);
            }
            /// <summary>
            /// Update the specified object
            /// </summary>
            public override TModel Update(ModelDataContext context, TModel data, IPrincipal principal)
            {
                foreach (var rp in typeof(TModel).GetRuntimeProperties().Where(o => typeof(IdentifiedData).GetTypeInfo().IsAssignableFrom(o.PropertyType.GetTypeInfo())))
                {
                    if (rp.GetCustomAttribute <DataIgnoreAttribute>() != null)
                    {
                        continue;
                    }

                    var instance = rp.GetValue(data);
                    if (instance != null)
                    {
                        DataModelExtensions.EnsureExists(instance as IdentifiedData, context, principal);
                        data.UpdateParentKeys(rp);
                    }
                }
                return(base.Update(context, data, principal));
            }