GetPrimaryKey() 공개 정적인 메소드

public static GetPrimaryKey ( Type T ) : IEnumerable
T System.Type
리턴 IEnumerable
예제 #1
0
        public Task <DeleteResult> DeleteAsync <T>(string Name, Type Type, T Document)
        {
            if (MongoMapperTransaction.InTransaction && !MongoMapperTransaction.Commiting)
            {
                MongoMapperTransaction.AddToQueue(OperationType.Delete, Type, Document);
                Task.FromResult(true);
            }

            var mongoMapperIdeable = Document as IMongoMapperIdeable;

            Debug.Assert(mongoMapperIdeable != null, "mongoMapperIdeable != null");

            if (mongoMapperIdeable.m_id == default(long))
            {
                mongoMapperIdeable.m_id = Finder.Instance.FindIdByKey <T>(Type,
                                                                          MongoMapperHelper.GetPrimaryKey(Type).
                                                                          ToDictionary(
                                                                              KeyField => KeyField,
                                                                              KeyField =>
                                                                              ReflectionUtility.
                                                                              GetPropertyValue(
                                                                                  this, KeyField)));
            }

            var query = Builders <T> .Filter.Eq("_id", mongoMapperIdeable.m_id);

            return(CollectionsManager.GetCollection <T>(Type.Name).DeleteOneAsync(query));
        }
예제 #2
0
        public T FindByKey <T>(params object[] Values)
        {
            List <string> fields    = MongoMapperHelper.GetPrimaryKey(typeof(T)).ToList();
            var           keyValues = new Dictionary <string, object>();

            for (int i = 0; i < fields.Count; i++)
            {
                string field = fields[i].ToUpper() == "m_id".ToUpper() ? "_id" : fields[i];
                keyValues.Add(field, Values[i]);
            }

            return(FindObjectByKey <T>(keyValues));
        }
 private Dictionary <string, object> GetPrimaryKeyValues()
 {
     return(MongoMapperHelper.GetPrimaryKey(_classType).ToDictionary(
                KeyField => KeyField, KeyField => ReflectionUtility.GetPropertyValue(this, KeyField)));
 }