/// <summary> /// Returns values for fields that represent row's primary key /// </summary> public IDataStoreKey GetDataStoreKey(string targetName = null) { var result = new NameValueDataStoreKey(); foreach (var kdef in Schema.GetKeyFieldDefsForTarget(targetName)) { result.Add(kdef.GetBackendNameForTarget(targetName), this[kdef.Order]); } return(result); }
public static void Delete(MongoDatabase db, ModelBase instance, IDataStoreKey key, object[] extra) { var record = asSuitableRecordInstance(instance); key = key ?? record.DataStoreKey; var nvkey = key as NameValueDataStoreKey; if (key != null && nvkey == null) { throw new MongoDBDataAccessException(string.Format(StringConsts.KEY_SUPPORT_ERROR)); } if (nvkey == null) { nvkey = new NameValueDataStoreKey(); foreach (var fld in record.Fields) { if (fld.KeyField) { nvkey.Add(fld.FieldName, fld.ValueAsObject); } } } var col = db.GetCollection <BsonDocument>(record.TableName); if (!col.Exists()) { throw new MongoDBDataAccessException(string.Format(StringConsts.COLLECTION_DOES_NOT_EXIST_ERROR, record.TableName)); } var query = nvkey != null?nvkey.ToMongoQuery() : Query.Null; var update = record.ToBSONUpdate(); col.Remove(query); }
public static void Delete(MongoDatabase db, ModelBase instance, IDataStoreKey key, object[] extra) { var record = asSuitableRecordInstance(instance); key = key ?? record.DataStoreKey; var nvkey = key as NameValueDataStoreKey; if (key!=null && nvkey==null) throw new MongoDBDataAccessException(string.Format(StringConsts.KEY_SUPPORT_ERROR)); if (nvkey==null) { nvkey = new NameValueDataStoreKey(); foreach(var fld in record.Fields) if(fld.KeyField) nvkey.Add(fld.FieldName, fld.ValueAsObject); } var col = db.GetCollection<BsonDocument>(record.TableName); if (!col.Exists()) throw new MongoDBDataAccessException(string.Format(StringConsts.COLLECTION_DOES_NOT_EXIST_ERROR, record.TableName)); var query = nvkey!=null ? nvkey.ToMongoQuery() : Query.Null; var update = record.ToBSONUpdate(); col.Remove(query); }