void CreateMethodFindById(IILGen ilGenerator, Type relationDBManipulatorType, string methodName, ParameterInfo[] methodParameters, Type methodReturnType, IDictionary <string, MethodInfo> apartFields, Action <IILGen> pushWriter, IILLocal writerLoc) { var isPrefixBased = ReturnsEnumerableOfClientType(methodReturnType, _relationInfo.ClientType); if (isPrefixBased) { WriteShortPrefixIl(ilGenerator, pushWriter, _relationInfo.Prefix); } else { WriteShortPrefixIl(ilGenerator, pushWriter, ObjectDB.AllRelationsPKPrefix); //ByteBufferWriter.WriteVUInt32(RelationInfo.Id); WriteIdIl(ilGenerator, pushWriter, (int)_relationInfo.Id); } var primaryKeyFields = _relationInfo.ClientRelationVersionInfo.GetPrimaryKeyFields(); var count = SaveMethodParameters(ilGenerator, methodName, methodParameters, methodParameters.Length, apartFields, primaryKeyFields, writerLoc); if (!isPrefixBased && count != primaryKeyFields.Count) { throw new BTDBException( $"Number of parameters in {methodName} does not match primary key count {primaryKeyFields.Count}."); } //call manipulator.FindBy_ ilGenerator .Ldarg(0); //manipulator //call byteBuffer.data var dataGetter = typeof(ByteBufferWriter).GetProperty("Data").GetGetMethod(true); ilGenerator.Ldloc(writerLoc).Call(dataGetter); if (isPrefixBased) { ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("FindByPrimaryKeyPrefix")); } else { ilGenerator.LdcI4(ShouldThrowWhenKeyNotFound(methodName, methodReturnType) ? 1 : 0); ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("FindByIdOrDefault")); if (methodReturnType == typeof(void)) { ilGenerator.Pop(); } } }