internal static object GetPrimaryKeyValue(DbContext context, object entity) { Microsoft.EntityFrameworkCore.Metadata.IKey key = context.Model.FindEntityType(entity.GetType().FullName).FindPrimaryKey(); if (key == null) { return(null); } return(key.Properties.Select(p => p.PropertyInfo.GetValue(entity)).FirstOrDefault()); }
public Key(Microsoft.EntityFrameworkCore.Metadata.IKey key, IEntityType entityType) { var keyProperties = new List <IProperty>(); foreach (var keyProperty in key.Properties) { keyProperties.Add(entityType.FindProperty(keyProperty.Name)); } Properties = keyProperties; }
private void SetPrimaryKey(Microsoft.EntityFrameworkCore.Metadata.IKey primaryKey) { PrimaryKey = new Key(primaryKey, this); }