none
2011 C# 程式问题 RRS feed

  • 问题

  • 我在CRM2011预设实体产品建立一笔的资料

    而有两个栏位是搜寻(N1关西

    搜寻对应实体已经资料,搜寻返回新增

    但是还会有栏位缺失,我已把必填都有给他

    下面是程式码

                    Entity location1 = new Entity("product");
                    location1["quantitydecimal"] = Int32.Parse("0");
                    location1["name"] = "aa"+ DateTime.Now.ToString("yyyyMMddmmss");
                    location1["productnumber"] = "123";


                    ConditionExpression condition1 = new ConditionExpression();
                    condition1.AttributeName = "name";
                    condition1.Operator = ConditionOperator.Like;
                    condition1.Values.AddRange(new object[] { "Quantity" }); ;

                    Microsoft.Xrm.Sdk.Query.FilterExpression filter1 = new Microsoft.Xrm.Sdk.Query.FilterExpression();
                    filter1.Conditions.Add(condition1);

                    QueryExpression qeLocations1 = new QueryExpression("uomschedule");
                    qeLocations1.ColumnSet = new ColumnSet(true);
                    qeLocations1.AddOrder("uomscheduleid", OrderType.Descending);
                    qeLocations1.Criteria.AddFilter(filter1);
                    var queryAns1 = tempOrganization.RetrieveMultiple(qeLocations1);

                    textBox1.Text += queryAns1.Entities.Count + Environment.NewLine;
                    foreach (var i in queryAns1.Entities)
                    {

                        EntityCollection roomCollection = new EntityCollection();
                        roomCollection.EntityName = "uomschedule"; //
                        roomCollection.Entities.Add(i);
                        Relationship roomRelationship = new Relationship("unit_of_measurement_schedule_products");
                        location1.RelatedEntities[roomRelationship] = roomCollection;
                    }

                    ConditionExpression condition2 = new ConditionExpression();
                    condition2.AttributeName = "name";
                    condition2.Operator = ConditionOperator.Like;
                    condition2.Values.AddRange(new object[] { "PCS%" }); ;

                    Microsoft.Xrm.Sdk.Query.FilterExpression filter2 = new Microsoft.Xrm.Sdk.Query.FilterExpression();
                    filter2.Conditions.Add(condition2);

                    QueryExpression qeLocations2 = new QueryExpression("uom");
                    qeLocations2.ColumnSet = new ColumnSet(true);
                    qeLocations2.AddOrder("uomid", OrderType.Descending);
                    qeLocations2.Criteria.AddFilter(filter2);
                    var queryAns2 = tempOrganization.RetrieveMultiple(qeLocations2);

                    textBox1.Text += queryAns2.Entities.Count + Environment.NewLine;
                    foreach (var j in queryAns2.Entities)
                    {
                        EntityCollection roomCollection1 = new EntityCollection();
                        roomCollection1.EntityName = "uomschedule";
                        roomCollection1.Entities.Add(aa);
                        Relationship roomRelationship1 = new Relationship("unit_of_measurement_products");
                        location1.RelatedEntities[roomRelationship1] = roomCollection1;
                    }

                   tempOrganization.Create(location1).ToString();

    当鏁搜寻搜寻2才可以进去
    请帮忙找寻错误点和说下如何修改

    2011年7月13日 2:33

答案

  • Relationship roomRelationship1 = new Relationship("unit_of_measurement_products");

    unit_of_measurement_products是单位跟产品关系

    roomCollection1.EntityName = "uomschedule";


    单位实体名称为UoM而不是uomschedule


    微软CRM
    • 已标记为答案 loueas 2011年7月15日 3:21
    2011年7月15日 2:59
    版主

全部回复

  • 报什么错误信息?


    微软CRM
    2011年7月15日 0:50
    版主
  • 错误讯息

    This entity cannot be added to the specified collection. The collection can have entities with PlatformName = UoMSchedule while this entity has Platform Name: UoM
    mscorlib

    Server stack trace:
       於 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       於 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       於 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       於 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       於 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       於 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       於 Microsoft.Xrm.Sdk.IOrganizationService.Create(Entity entity)
       於 Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.CreateCore(Entity entity)
       於 Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Create(Entity entity)
       於 WindowsFormsApplication2.Form1.button6_Click(Object sender, EventArgs e) 於 C:\Users\loueas\Desktop\新增資料夾 (2)\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs: 行 866


    Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)

    2011年7月15日 1:47
  • Relationship roomRelationship1 = new Relationship("unit_of_measurement_products");

    unit_of_measurement_products是单位跟产品关系

    roomCollection1.EntityName = "uomschedule";


    单位实体名称为UoM而不是uomschedule


    微软CRM
    • 已标记为答案 loueas 2011年7月15日 3:21
    2011年7月15日 2:59
    版主
  • 查找属性赋值方式:

    location1["defaultuomid"] = new EntityReference("uom", guid of a uomid record);


    微软CRM
    2011年7月15日 3:05
    版主
  • 感謝~~已經解決了

     

    2011年7月15日 3:21
  • 在请问一下吗?有的搜寻栏位没有值回传回来是在实体那些地方去做设定或是修改程式
    2011年7月18日 2:02