public virtual IEntityConfiguration <TEntity> AsDefault() { var defaultKey = SimpleSaveConfiguration.Configuration.DefaultKeyName; var props = _configuration.DtoType.Properties(Flags.InstancePublic) .Where(x => !_configuration.Properties.ContainsKey(x.Name)) .ToList(); props.ForEach(p => { var metadata = new PropertyMetadataExt(p); if (p.Name.Equals(defaultKey, StringComparison.OrdinalIgnoreCase) && _configuration.Key == null) { _configuration.Key = new PropertyMetadataExt(p) { IsPrimaryKey = true }; return; } _configuration.Properties.Add(p.Name, metadata); }); if (_configuration.Key == null) { throw new Exception($"Primary key for {nameof(TEntity)} not found. Default key name is {defaultKey}"); } return(this); }
protected IPropertyMetadataExt GetPropMetadata(MemberExpression memberExpr) { IPropertyMetadataExt metadata; if (_configuration.Key != null && _configuration.Key.Name.Equals(memberExpr.Member.Name)) { return(_configuration.Key); } if (_configuration.Properties.ContainsKey(memberExpr.Member.Name)) { metadata = _configuration.Properties[memberExpr.Member.Name]; } else { metadata = new PropertyMetadataExt((PropertyInfo)memberExpr.Member); _configuration.Properties.Add(memberExpr.Member.Name, metadata); } return(metadata); }