本文整理汇总了C#中System.Entity.CreateProperties方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.CreateProperties方法的具体用法?C# Entity.CreateProperties怎么用?C# Entity.CreateProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.CreateProperties方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBaseCommand
private DbCommand CreateBaseCommand(Entity entity)
{
var sbKeys = new StringBuilder();
var sbVals = new StringBuilder();
var cmd = DB.CreateCommand();
var counter = 0;
foreach (var property in entity
.CreateProperties(getForeignCollection: false)
.WhereIsNotSkipped())
{
sbKeys.AppendFormat("{0},", property.ColumnName);
sbVals.AppendFormat("@{0},", counter);
AddParam(cmd, property);
counter++;
}
var keys = sbKeys.ToString().Substring(0, sbKeys.Length - 1);
var vals = sbVals.ToString().Substring(0, sbVals.Length - 1);
var idType = "int";
var insertedId = "SCOPE_IDENTITY()";
if (entity.Key.Count > 1 || entity.Key.FirstOrDefault().TypeInfo.IsString)
{
idType = "nvarchar(max)";
insertedId = "@" + counter;
cmd.AddParam(entity.JoinedKeyValue);
}
var sql = SqlFormat.Fill(entity.TableName, keys, vals, idType, insertedId);
cmd.CommandText = sql;
return cmd;
}
示例2: GetEntityWithData
public Entity GetEntityWithData(Entity entity, params string[] key)
{
var keys = new object[key.Length];
for (int i = 0; i < key.Length; i++)
{
keys[i] = entity.Key[i].Value.ToObject(key[i]);
}
var item = GetRecord(entity, keys);
if (item == null)
{
_notificator.Error(IlaroAdminResources.EntityNotExist);
return null;
}
var propertiesDict = item as IDictionary<string, object>;
foreach (var property in entity.CreateProperties(false))
{
property.Value.Raw =
propertiesDict.ContainsKey(property.ColumnName.Undecorate()) ?
propertiesDict[property.ColumnName.Undecorate()] :
null;
}
return entity;
}
示例3: CreateBaseCommand
protected virtual DbCommand CreateBaseCommand(Entity entity)
{
var sbKeys = new StringBuilder();
var cmd = DB.CreateCommand();
var counter = 0;
var updateProperties = entity.CreateProperties(getForeignCollection: false)
.Where(x => x.IsKey == false)
.WhereIsNotSkipped().ToList();
if (updateProperties.Any())
{
foreach (var property in updateProperties)
{
AddParam(cmd, property);
sbKeys.AppendFormat("\t{0} = @{1}, \r\n", property.ColumnName, counter++);
}
cmd.AddParams(entity.Key.Select(x => x.Value.Raw).ToArray());
var keys = sbKeys.ToString().Substring(0, sbKeys.Length - 4);
var whereParts = new List<string>();
foreach (var key in entity.Key)
{
whereParts.Add("{0} = @{1}".Fill(key.ColumnName, counter++));
}
var wherePart = string.Join(" AND ", whereParts);
cmd.CommandText = SqlFormat.Fill(entity.TableName, keys, wherePart);
}
cmd.AddParam(entity.JoinedKeyValue);
cmd.CommandText += SqlReturnRecordIdPart.Fill(counter);
return cmd;
}
示例4: GetEntityHierarchy
private EntityHierarchy GetEntityHierarchy(
EntityHierarchy parent,
Entity entity,
ref int index)
{
var hierarchy = new EntityHierarchy
{
Entity = entity,
Alias = "[t" + index + "]",
SubHierarchies = new List<EntityHierarchy>(),
ParentHierarchy = parent
};
foreach (var property in entity.CreateProperties()
.Where(x => x.IsForeignKey && x.TypeInfo.IsCollection)
.Where(property =>
parent == null ||
parent.Entity != property.ForeignEntity))
{
index++;
var subHierarchy =
GetEntityHierarchy(hierarchy, property.ForeignEntity, ref index);
hierarchy.SubHierarchies.Add(subHierarchy);
}
return hierarchy;
}
示例5: PrepareGroups
public IList<GroupProperties> PrepareGroups(Entity entity, bool getKey = true, string key = null)
{
var properties = entity.CreateProperties(getKey);
foreach (var foreign in properties.Where(x => x.IsForeignKey))
{
var records = _source.GetRecords(foreign.ForeignEntity, determineDisplayValue: true).Records;
foreign.Value.PossibleValues = records.ToDictionary(x => x.JoinedKeyValue, x => x.DisplayName);
if (foreign.TypeInfo.IsCollection)
{
foreign.Value.Values = records
.Where(x => x.Values.Any(y => y.Property.ForeignEntity == entity && y.AsString == key))
.Select(x => x.JoinedKeyValue)
.OfType<object>()
.ToList();
}
}
return entity.Groups;
}
示例6: Delete
public bool Delete(Entity entity, string key, IEnumerable<PropertyDeleteOption> options)
{
var existingRecord = _source.GetRecord(entity, key);
if (existingRecord == null)
{
_notificator.Error(IlaroAdminResources.EntityNotExist);
return false;
}
entity.SetKeyValue(key);
options = options ?? new List<PropertyDeleteOption>();
var deleteOptions = options.ToDictionary(x => x.PropertyName, x => x.DeleteOption);
foreach (var property in entity.GetForeignsForUpdate())
{
if (!deleteOptions.ContainsKey(property.ForeignEntity.Name))
{
deleteOptions[property.ForeignEntity.Name] = property.DeleteOption;
}
}
var result = _deleter.Delete(entity, deleteOptions, () => _changeDescriber.DeleteChanges(entity, existingRecord));
if (result)
{
var propertiesWithFilesToDelete = entity
.CreateProperties(getForeignCollection: false)
.Where(x => x.TypeInfo.IsFile && x.TypeInfo.IsFileStoredInDb == false);
_filesHandler.Delete(propertiesWithFilesToDelete);
}
return result;
}
示例7: CreateBaseCommand
protected virtual DbCommand CreateBaseCommand(Entity entity)
{
var sbKeys = new StringBuilder();
var cmd = DB.CreateCommand();
var counter = 0;
foreach (var property in
entity.CreateProperties(getForeignCollection: false).Where(x => x.IsKey == false))
{
AddParam(cmd, property);
sbKeys.AppendFormat("\t{0} = @{1}, \r\n", property.ColumnName, counter);
counter++;
}
cmd.AddParam(entity.Key.Value.Raw);
var keys = sbKeys.ToString().Substring(0, sbKeys.Length - 4);
cmd.CommandText = SqlFormat.Fill(entity.TableName, keys, entity.Key.ColumnName, counter);
return cmd;
}
示例8: Upload
/// <summary>
/// Upload files to temp location, or save file byte array to property value
/// </summary>
public IList<Property> Upload(Entity entity)
{
var proccessedProperties = new List<Property>();
foreach (var property in entity
.CreateProperties(getForeignCollection: false)
.Where(x => x.TypeInfo.IsFile))
{
if (property.Value.Raw.IsBehavior(DataBehavior.Clear))
{
property.Value.Raw = property.Value.DefaultValue;
proccessedProperties.Add(property);
continue;
}
var file = (HttpPostedFileWrapper)property.Value.Raw;
if (file == null || file.ContentLength == 0)
{
property.Value.Raw = DataBehavior.Skip;
continue;
}
if (property.TypeInfo.IsFileStoredInDb)
{
var setting = property.FileOptions.Settings.FirstOrDefault();
var fileInputStream = property.TypeInfo.IsImage ?
_resizer.Resize(file.InputStream, setting.Width, setting.Height) :
file.InputStream;
var bytes = _saver.GetFileByteArray(fileInputStream);
property.Value.Raw = bytes;
}
else
{
var fileName = _fileNameCreator.GetFileName(property, file);
property.Value.Raw = fileName;
if (property.TypeInfo.IsImage)
{
foreach (var setting in property.FileOptions.Settings)
{
var resizedStream = _resizer.Resize(
file.InputStream,
setting.Width,
setting.Height);
var subPath =
setting.SubPath.TrimEnd('/', '\\') +
_configuration.UploadFilesTempFolderSufix;
var path = Path.Combine(BasePath, property.FileOptions.Path, subPath, fileName);
_saver.SaveFile(resizedStream, path);
resizedStream.Dispose();
}
}
else
{
var subPath =
property.FileOptions.Path.TrimEnd('/', '\\') +
_configuration.UploadFilesTempFolderSufix;
var path = Path.Combine(BasePath, subPath, fileName);
_saver.SaveFile(file.InputStream, path);
}
proccessedProperties.Add(property);
}
file.InputStream.Dispose();
}
return proccessedProperties;
}