}//method public static EntityRecord GetEntityRefTarget(EntityRecord record, EntityMemberInfo member) { // Current value is null (meaning not set, yet). We must figure it out. // 1. If corresponding FK is null, then value is DbNull. var fromKey = member.ReferenceInfo.FromKey; var toKey = member.ReferenceInfo.ToKey; if (!record.KeyIsLoaded(fromKey) && record.Status != EntityStatus.New) { record.Reload(); } if (record.KeyIsNull(fromKey)) { return(null); } // 2. The key is not null, let's lookup the record by FK; maybe it was already loaded var fkValue = new EntityKey(fromKey, record); var targetEntity = toKey.Entity; //Compute pkValue on target entity var pkValue = new EntityKey(targetEntity.PrimaryKey, fkValue.Values); //If Session available, ask session for existing record EntityRecord targetRec; if (record.Session != null) { targetRec = record.Session.GetRecord(pkValue, LoadFlags.Stub); //either already loaded or a stub } else { targetRec = new EntityRecord(pkValue); //create detached stub } return(targetRec); }//method
private void SetCrudCommandParameterValues(DbCommandInfo commandInfo, IDbCommand command, EntityRecord record) { if (record.Status == EntityStatus.Stub) { record.Reload(); } for (int i = 0; i < commandInfo.Parameters.Count; i++) { var prm = (IDbDataParameter)command.Parameters[i]; prm.Value = DBNull.Value; var prmInfo = commandInfo.Parameters[i]; var isInput = prmInfo.Direction == ParameterDirection.Input || prmInfo.Direction == ParameterDirection.InputOutput; if (!isInput) { continue; } var col = prmInfo.SourceColumn; if (col == null || col.Member == null) { continue; } var value = record.GetValueDirect(col.Member); if (value == null) { value = DBNull.Value; } var conv = prmInfo.TypeInfo.PropertyToColumnConverter; if (value != DBNull.Value && conv != null) { value = conv(value); } prm.Value = value; } //for i }
public static object GetSimpleValue(EntityRecord record, EntityMemberInfo member) { var value = record.GetValueDirect(member); if (value == null && record.Status != EntityStatus.New) { record.Reload(); value = record.GetValueDirect(member); } if (value == DBNull.Value) { return(null); } return(value); }