浏览代码

Fixing problems

Kenric Nugteren 1 年之前
父节点
当前提交
6201718d1d

+ 24 - 42
InABox.Core/Column.cs

@@ -34,11 +34,21 @@ namespace InABox.Core
     {
         private IProperty _property;
 
-        public Type Type => _property.PropertyType;
+        public Type Type
+        {
+            get
+            {
+                if (Expression is null)
+                    throw new Exception($"Expression [{Property}] may not be null");
+                if (Expression is IndexExpression)
+                    return DatabaseSchema.Property(typeof(T), Property).PropertyType;
+                return Expression.Type;
+            }
+        }
 
-        public string Property => _property.Name;
+        public string Property { get; private set; }
 
-        public Expression Expression => _property.Expression();
+        public Expression Expression { get; private set; }
 
         public bool IsEqualTo(string name) => 
             !name.IsNullOrWhiteSpace() && Property.Equals(name);
@@ -50,19 +60,25 @@ namespace InABox.Core
 
         public Column(IProperty property)
         {
-            _property = property;
+            Property = property.Name;
+            Expression = property.Expression();
         }
 
         public Column(Expression<Func<T, object?>> expression)
         {
-            _property = DatabaseSchema.Property(expression)
-                ?? throw new Exception($"Property {CoreUtils.GetFullPropertyName(expression, ".")} not found.");
+            Property = CoreUtils.GetFullPropertyName(expression, ".");
+            Expression = CoreUtils.ExtractMemberExpression(expression);
         }
 
         public Column(string property)
         {
-            _property = DatabaseSchema.Property(typeof(T), property)
-                ?? throw new Exception($"Property {property} not found.");
+            Property = property;
+
+            var iprop = DatabaseSchema.Property(typeof(T), property);
+            if (iprop != null)
+                Expression = iprop.Expression();
+            else
+                Expression = CoreUtils.CreateMemberExpression(typeof(T), property);
         }
 
         public Column<TNew> Cast<TNew>()
@@ -106,40 +122,6 @@ namespace InABox.Core
         IEnumerator<IColumn> GetEnumerator();
     }
 
-    public enum ColumnType
-    {
-        //ExcludeVisible,
-        /// <summary>
-        /// Do not include <see cref="Entity.ID"/> in the columns.
-        /// </summary>
-        ExcludeID,
-        IncludeOptional,
-        IncludeForeignKeys,
-        /// <summary>
-        /// Include all columns that are accessible through entity links present in the root class.
-        /// </summary>
-        IncludeLinked,
-        IncludeAggregates,
-        IncludeFormulae,
-        /// <summary>
-        /// Include any columns that are a <see cref="CustomProperty"/>.
-        /// </summary>
-        IncludeUserProperties,
-        /// <summary>
-        /// Include all columns that are accessible through entity links, even nested ones.
-        /// </summary>
-        IncludeNestedLinks,
-        IncludeEditable,
-        /// <summary>
-        /// Add all columns that are data actually on the entity, and not on entity links or calculated fields.
-        /// </summary>
-        DataColumns,
-        /// <summary>
-        /// Add all columns found.
-        /// </summary>
-        All
-    }
-
     [Flags]
     public enum ColumnTypeFlags
     {

+ 7 - 0
InABox.Core/DatabaseSchema/CustomProperty.cs

@@ -122,6 +122,7 @@ namespace InABox.Core
 
                 IsEntityLink = type.GetInterfaces().Contains(typeof(IEntityLink));
                 IsEnclosedEntity = type.GetInterfaces().Contains(typeof(IEnclosedEntity));
+                IsParent = IsEntityLink || IsEnclosedEntity;
 
                 RegenerateEditor();
             }
@@ -139,6 +140,7 @@ namespace InABox.Core
                 Editor = null;
                 IsEntityLink = type.GetInterfaces().Contains(typeof(IEntityLink));
                 IsEnclosedEntity = type.GetInterfaces().Contains(typeof(IEnclosedEntity));
+                IsParent = IsEntityLink || IsEnclosedEntity;
 
                 RegenerateEditor();
             }
@@ -212,6 +214,11 @@ namespace InABox.Core
         [DoNotSerialize]
         public bool IsEnclosedEntity { get; set; }
 
+        [NullEditor]
+        [DoNotPersist]
+        [DoNotSerialize]
+        public bool IsParent { get; set; }
+
         [NullEditor]
         [DoNotPersist]
         [DoNotSerialize]

+ 2 - 0
InABox.Core/DatabaseSchema/IProperty.cs

@@ -55,6 +55,8 @@ namespace InABox.Core
 
         bool IsEnclosedEntity { get; set; }
 
+        bool IsParent { get; set; }
+
         Expression Expression();
 
         Func<object, object> Getter();

+ 3 - 0
InABox.Core/DatabaseSchema/StandardProperty.cs

@@ -84,6 +84,7 @@ namespace InABox.Core
                 _type = value.EntityName();
                 IsEntityLink = _propertyType.GetInterfaces().Contains(typeof(IEntityLink));
                 IsEnclosedEntity = _propertyType.GetInterfaces().Contains(typeof(IEnclosedEntity));
+                IsParent = IsEnclosedEntity || IsEntityLink;
             }
         }
 
@@ -131,6 +132,8 @@ namespace InABox.Core
 
         public bool IsEnclosedEntity { get; set; }
 
+        public bool IsParent { get; set; }
+
         public bool IsCalculated
         {
             get

+ 3 - 2
inabox.database.sqlite/SQLiteProvider.cs

@@ -2011,9 +2011,10 @@ namespace InABox.Database.SQLite
                         {
                             var linkedType = prop.PropertyType.GetInheritedGenericTypeArguments().First();
                             var remote = linkedType.GetProperty(bits.Last());
+                            var enclosingProperty = string.Join(".", bits.Take(combinecount)) + ".";
 
                             // Are there any other properties for this link?  These will form the columns for our subquery
-                            var siblings = columns.Where(x => x.Split('.').First().Equals(bits.First()))
+                            var siblings = columns.Where(x => x.StartsWith(enclosingProperty))
                                 .Select(x => string.Join(".", x.Split('.').Skip(combinecount))).ToList();
                             if (remote != null && !siblings.Contains(remote.Name))
                                 siblings.Add(remote.Name);
@@ -2570,7 +2571,7 @@ namespace InABox.Database.SQLite
                     }
                     catch (Exception e)
                     {
-                        OnLog?.Invoke(LogType.Error, e.Message);
+                        OnLog?.Invoke(LogType.Error, $"{e.Message}: {sql}");
                     }
                     //LogStop("ReadData");
 

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicGridUtils.cs

@@ -344,7 +344,7 @@ public static class DynamicGridUtils
         foreach (var col in additional)
             result.Add(col.Property);
 
-        foreach (var col in result)
+        foreach (var col in result.ToArray())
         {
             var prop = DatabaseSchema.Property(typeof(T), col.Property);
             if (prop?.Editor is DataLookupEditor dataLookup)