Dynamics crm 2011 如何以XML而不是实体的形式访问FetchXML的结果?

Dynamics crm 2011 如何以XML而不是实体的形式访问FetchXML的结果?,dynamics-crm-2011,fetchxml,Dynamics Crm 2011,Fetchxml,在过去,我的FetchXML以xml格式向我传递结果,但是由于我更改了服务器,所以这个函数string ret=service.Fetch(FetchXML)不再有效,所以我不得不求助于另一个解决方案,但这一个给了我更多的工作来构建XML文件 获取字符串示例: string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

在过去,我的FetchXML以xml格式向我传递结果,但是由于我更改了服务器,所以这个函数
string ret=service.Fetch(FetchXML)
不再有效,所以我不得不求助于另一个解决方案,但这一个给了我更多的工作来构建XML文件

获取字符串示例:

 string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
        <entity name='account'>
        <attribute name='name'/>
        <attribute name='telephone1'/>
        </entity>
        </fetch>";

        EntityCollection ec = organizationProxy.RetrieveMultiple(new FetchExpression(fetchXml));


        XElement rootXml = new XElement("account");
        foreach (Entity account in ec.Entities)
        {
            if (account.Attributes.Contains("name"))
            {
                rootXml.Add(new XElement("name", account.Attributes.Contains("name") ? account["name"] : ""));
                rootXml.Add(new XElement("telephone1", account.Attributes.Contains("telephone1") ? account["telephone1"] : ""));
            }
        }

        res.XmlContent = rootXml.ToString();
string fetchXml=@”

)但这给了我比代码更多的工作。或者没有其他解决方案?

在过去,我使用序列化将对象转换为XML并再次转换

转换为XML的步骤

        public static string SerializeAnObject(object _object)
        {
            System.Xml.XmlDocument doc = new XmlDocument();
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(_object.GetType());
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            try
            {
                serializer.Serialize(stream, _object);
                stream.Position = 0;
                doc.Load(stream);
                return doc.InnerXml;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                stream.Close();
                stream.Dispose();
            }
        }
将其转换回实体集合(或其他对象)的步骤


在过去,我使用序列化将对象转换为XML,然后再转换回来

转换为XML的步骤

        public static string SerializeAnObject(object _object)
        {
            System.Xml.XmlDocument doc = new XmlDocument();
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(_object.GetType());
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            try
            {
                serializer.Serialize(stream, _object);
                stream.Position = 0;
                doc.Load(stream);
                return doc.InnerXml;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                stream.Close();
                stream.Dispose();
            }
        }
将其转换回实体集合(或其他对象)的步骤