public GetColumnValuesForAlias ( string alias ) : IList |
||
alias | string | |
return | IList |
private object CreateInstance(Type type, Row row, EntityCache entityCache, string alias = null) { var instance = CreateInstance(type); IList <ColumnValue> columnValuesForType; if (String.IsNullOrWhiteSpace(alias)) { columnValuesForType = row.GetColumnValuesForType(type, _conventionReader); } else { columnValuesForType = row.GetColumnValuesForAlias(alias); } var columnValuesForCurrentType = columnValuesForType .Where(x => !_conventionReader.IsEntityReferenceProperty(x.ColumnName, type)) .ToList(); if (columnValuesForCurrentType.Any() && columnValuesForCurrentType.All(x => x.Value == null)) { return(null); } foreach (var columnValue in columnValuesForCurrentType) { var property = GetProperty(type, columnValue); property.SetValue(instance, columnValue.Value, null); } var includesPrimaryKeyColumn = QueryIncludesPrimaryKeyColumn(type, row, alias); // If the query does not include the primary key column we can't know if // the cache already contains the entity or not, since we do not have anything // unique to match the entities on. So, treat all rows as different to make sure // no rows are incorrectly merged into one, which would be the case if we assumed // that they represented the same entity. if (entityCache.Contains(instance) && includesPrimaryKeyColumn) { return(entityCache.GetExisting(instance)); } entityCache.Add(instance); return(instance); }
private bool QueryIncludesPrimaryKeyColumn(Type type, Row row, string primaryAlias) { var primaryKeyColumnName = _conventionReader.TryGetPrimaryKeyColumnName(type); var typeHasIdProperty = primaryKeyColumnName != null; IList <ColumnValue> columnValuesForType; if (primaryAlias.IsNullOrWhiteSpace()) { columnValuesForType = row.GetColumnValuesForType(type, _conventionReader); } else { columnValuesForType = row.GetColumnValuesForAlias(primaryAlias); } var resultIncludesPrimaryKeyColumn = columnValuesForType.Any(x => x.ColumnName == primaryKeyColumnName); return(typeHasIdProperty && resultIncludesPrimaryKeyColumn); }