예제 #1
0
        public static object ProxyObject(this EntityObjectStore.LocalContext context, object objectToProxy)
        {
            if (TypeUtils.IsProxy(objectToProxy.GetType()))
            {
                return(objectToProxy);
            }

            object newObject = context.GetObjectSet(objectToProxy.GetType()).CreateObject();

            PropertyInfo[] idMembers = context.GetIdMembers(objectToProxy.GetType());

            idMembers.ForEach(pi => newObject.GetType().GetProperty(pi.Name).SetValue(newObject, pi.GetValue(objectToProxy, null), null));

            return(context.GetObjectSet(objectToProxy.GetType()).ApplyCurrentValues((dynamic)newObject));
        }
예제 #2
0
        public static object CreateObject(this EntityObjectStore.LocalContext context, Type type)
        {
            object objectSet = context.GetObjectSet(type);
            var    methods   = objectSet.GetType().GetMethods();
            var    mi        = methods.Single(m => m.Name == "CreateObject" && m.IsGenericMethod).MakeGenericMethod(type);

            return(InvokeUtils.Invoke(mi, objectSet, null));
        }
예제 #3
0
        public static object GetNextKey(this EntityObjectStore.LocalContext context, Type type)
        {
            PropertyInfo idMember = context.GetIdMembers(type).Single();
            string       query    = string.Format("max(it.{0}) + 1", idMember.Name);

            dynamic os = context.GetObjectSet(type);
            ObjectQuery <DbDataRecord> results = os.Select(query);
            DbDataRecord result = results.Single();

            return(GetNextKey(type, result.IsDBNull(0) ? 1 : (int)result[0]));
        }