コード例 #1
0
            /// <summary>
            /// Update the specified object
            /// </summary>
            protected override TModel UpdateInternal(SQLiteDataContext context, TModel data)
            {
                if (data.IsEmpty())
                {
                    return(data);
                }

                foreach (var rp in this.m_properties)
                {
                    var instance = rp.GetValue(data);
                    if (instance != null && rp.Name != "SourceEntity") // HACK: Prevent infinite loops on associtive entities
                    {
                        instance = ModelExtensions.TryGetExisting(instance as IIdentifiedEntity, context);
                        if (instance != null)
                        {
                            rp.SetValue(data, instance);
                        }
                        ModelExtensions.UpdateParentKeys(data, rp);
                    }
                }
                return(base.UpdateInternal(context, data));
            }
コード例 #2
0
            /// <summary>
            /// Ensure exists
            /// </summary>
            protected override TModel InsertInternal(SQLiteDataContext context, TModel data)
            {
                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)
                    {
                        instance = ModelExtensions.TryGetExisting(instance as IIdentifiedEntity, context);
                        if (instance != null)
                        {
                            rp.SetValue(data, instance);
                        }
                        ModelExtensions.UpdateParentKeys(data, rp);
                    }
                }
                return(base.InsertInternal(context, data));
            }
コード例 #3
0
            /// <summary>
            /// Ensure exists
            /// </summary>
            protected override TModel InsertInternal(SQLiteDataContext context, TModel data)
            {
                if (data.IsEmpty())
                {
                    return(data);
                }

                foreach (var rp in this.m_properties)
                {
                    var instance = rp.GetValue(data);
                    if (instance != null)
                    {
                        instance = ModelExtensions.TryGetExisting(instance as IIdentifiedEntity, context);
                        if (instance != null)
                        {
                            rp.SetValue(data, instance);
                        }

                        ModelExtensions.UpdateParentKeys(data, rp);
                    }
                }
                return(base.InsertInternal(context, data));
            }