/// <summary>
 /// Set defaults for database generated properties when no property is selected.
 /// </summary>
 /// <param name="excludeDbGeneratedByDefault"></param>
 /// <returns></returns>
 public virtual MergeInsertArgs <TEntity> SetExcludeDbGeneratedByDefault(
     ExcludeOptions excludeDbGeneratedByDefault)
 {
     ExcludeDbGeneratedByDefault = excludeDbGeneratedByDefault;
     return(this);
 }
示例#2
0
        //Filtering and ordering
        public List <MappedProperty> FilterProperties(List <MappedProperty> properties, bool hasOtherConditions
                                                      , List <string> includeProperties, List <string> excludeProperties
                                                      , bool excludeAllByDefault, ExcludeOptions includeDbGeneratedProperties)
        {
            List <MappedProperty> selectedProperties;

            if (includeProperties.Count > 0 || hasOtherConditions)
            {
                selectedProperties = properties.Where(
                    pr => pr.IsComplexProperty ||
                    includeProperties.Contains(pr.EfDefaultName))
                                     .ToList();
            }
            else if (excludeProperties.Count > 0)
            {
                selectedProperties = properties.Where(
                    pr => pr.IsComplexProperty ||
                    !excludeProperties.Contains(pr.EfDefaultName))
                                     .ToList();
            }
            else if (excludeAllByDefault)
            {
                selectedProperties = new List <MappedProperty>();

                if (includeDbGeneratedProperties == ExcludeOptions.Include)
                {
                    List <string> generatedProps = _context.GetDatabaseGeneratedProperties(_rootEntityType);
                    selectedProperties = properties
                                         .Where(x => generatedProps.Contains(x.EfMappedName))
                                         .ToList();
                }
            }
            else //include all by default
            {
                selectedProperties = properties;

                if (includeDbGeneratedProperties == ExcludeOptions.Exclude)
                {
                    List <string> generatedProps = _context.GetDatabaseGeneratedProperties(_rootEntityType);
                    selectedProperties = selectedProperties
                                         .Where(x => !generatedProps.Contains(x.EfMappedName))
                                         .ToList();
                }
            }

            //exclude properties that are not mapped to any column
            selectedProperties = selectedProperties.Where(
                pr => pr.IsComplexProperty ||
                pr.EfMappedName != null)
                                 .ToList();

            for (int i = 0; i < selectedProperties.Count; i++)
            {
                if (selectedProperties[i].IsComplexProperty)
                {
                    MappedProperty copy = selectedProperties[i].Copy();
                    copy.ChildProperties = FilterProperties(selectedProperties[i].ChildProperties, hasOtherConditions
                                                            , includeProperties, excludeProperties, excludeAllByDefault, includeDbGeneratedProperties);
                    selectedProperties[i] = copy;
                }
            }

            return(selectedProperties);
        }
 /// <summary>
 /// Set defaults for database generated properties when no property is selected.
 /// </summary>
 /// <param name="excludeDbGeneratedByDefault"></param>
 /// <returns></returns>
 public virtual MergeCompareArgs<TEntity> SetExcludeDbGeneratedByDefault(
     ExcludeOptions excludeDbGeneratedByDefault)
 {
     ExcludeDbGeneratedByDefault = excludeDbGeneratedByDefault;
     return this;
 }