public virtual EntityRecord GetRecord(EntityKey primaryKey, LoadFlags flags = LoadFlags.Default) { if (primaryKey == null || primaryKey.IsNull()) { return(null); } var record = GetLoadedRecord(primaryKey); if (record != null) { if (record.Status == EntityStatus.Stub && flags.IsSet(LoadFlags.Load)) { record.Reload(); } return(record); } // TODO: review returning Record stub in the context of SecureSession. // We might have security hole here if user is not authorized to access the record if (flags.IsSet(LoadFlags.Stub)) { return(CreateStub(primaryKey)); } if (!flags.IsSet(LoadFlags.Load)) { return(null); } //Otherwise, load it var ent = this.SelectByPrimaryKey(primaryKey.KeyInfo.Entity, primaryKey.Values); return(ent?.Record); }
//Creates a stub public EntityRecord(EntityKey primaryKey) : this(primaryKey.KeyInfo.Entity, EntityStatus.Stub) { //sanity check Util.Check(!primaryKey.IsNull(), "Primary key values are empty - cannot create a stub. Entity: {0}", EntityInfo.Name); _primaryKey = primaryKey; //copy primary key var keyInfo = primaryKey.KeyInfo; for (int i = 0; i < keyInfo.ExpandedKeyMembers.Count; i++) { var member = keyInfo.ExpandedKeyMembers[i].Member; var v = primaryKey.Values[i]; ValuesOriginal[member.ValueIndex] = v; } }