当前位置: 首页>>代码示例>>C#>>正文


C# Entity.ToEntityReference方法代码示例

本文整理汇总了C#中System.Entity.ToEntityReference方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.ToEntityReference方法的具体用法?C# Entity.ToEntityReference怎么用?C# Entity.ToEntityReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Entity的用法示例。


在下文中一共展示了Entity.ToEntityReference方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: When_executing_a_query_expression_with_a_simple_join_right_result_is_returned

        public void When_executing_a_query_expression_with_a_simple_join_right_result_is_returned()
        {
            var context = new XrmFakedContext();
            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2";
            
            var account = new Entity("account") { Id = Guid.NewGuid() };
            account["name"] = "Account 1";

            contact1["parentcustomerid"] = account.ToEntityReference(); //Both contacts are related to the same account
            contact2["parentcustomerid"] = account.ToEntityReference();

            context.Initialize(new List<Entity>() { account, contact1, contact2});

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.LinkEntities.Add(
                new LinkEntity()
                {
                    LinkFromEntityName = "contact",
                    LinkToEntityName = "account",
                    LinkFromAttributeName = "parentcustomerid",
                    LinkToAttributeName = "accountid",
                    JoinOperator = JoinOperator.Inner,
                    Columns = new ColumnSet(new string[] { "name" })
                }
            );
            qe.ColumnSet = new ColumnSet(new string[] { "fullname", "parentcustomerid" });

            var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe);

            Assert.True(result.Count() == 2); //2 Contacts related to the same account
            var firstContact = result.FirstOrDefault();
            var secondContact = result.LastOrDefault();

            Assert.True(firstContact.Attributes.Count == 3);
            Assert.True(secondContact.Attributes.Count == 3);

            Assert.True(firstContact["fullname"].Equals(contact1["fullname"]));
            Assert.True((firstContact["account.name"] as AliasedValue).Value.Equals(account["name"]));

            Assert.True(secondContact["fullname"].Equals(contact2["fullname"]));
            Assert.True((secondContact["account.name"] as AliasedValue).Value.Equals(account["name"]));

        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:44,代码来源:FakeContextTestTranslateQueryExpression.cs

示例2: When_executing_a_query_expression_only_the_selected_columns_in_the_columnset_are_returned

        public void When_executing_a_query_expression_only_the_selected_columns_in_the_columnset_are_returned()
        {
            var context = new XrmFakedContext();
            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";
            var contact3 = new Entity("contact") { Id = Guid.NewGuid() }; contact3["fullname"] = "Contact 3"; contact3["firstname"] = "First 3";

            var account = new Entity("account") { Id = Guid.NewGuid() };
            account["name"] = "Account 1";

            contact1["parentcustomerid"] = account.ToEntityReference(); //Both contacts are related to the same account
            contact2["parentcustomerid"] = account.ToEntityReference();

            context.Initialize(new List<Entity>() { account, contact1, contact2, contact3 });

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.LinkEntities.Add(
                new LinkEntity()
                {
                    LinkFromEntityName = "contact",
                    LinkToEntityName = "account",
                    LinkFromAttributeName = "parentcustomerid",
                    LinkToAttributeName = "accountid",
                    JoinOperator = JoinOperator.Inner,
                    Columns = new ColumnSet(new string[] { "name" })
                }
            );

            //We only select fullname and parentcustomerid, firstname should not be included
            qe.ColumnSet = new ColumnSet(new string[] { "fullname", "parentcustomerid" });

            var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe);

            Assert.True(result.Count() == 2);
            var firstContact = result.FirstOrDefault();
            var lastContact = result.LastOrDefault();

            Assert.False(firstContact.Attributes.ContainsKey("firstname"));
            Assert.False(lastContact.Attributes.ContainsKey("firstname"));
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:40,代码来源:FakeContextTestTranslateQueryExpression.cs

示例3: When_executing_a_query_expression_join_with_orphans_these_are_not_returned

        public void When_executing_a_query_expression_join_with_orphans_these_are_not_returned()
        {
            var context = new XrmFakedContext();
            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2";
            var contact3 = new Entity("contact") { Id = Guid.NewGuid() }; contact3["fullname"] = "Contact 3";

            var account = new Entity("account") { Id = Guid.NewGuid() };
            account["name"] = "Account 1";

            contact1["parentcustomerid"] = account.ToEntityReference(); //Both contacts are related to the same account
            contact2["parentcustomerid"] = account.ToEntityReference();

            //Contact3 doesnt have a parent customer, but must be returned anyway (left outer)

            context.Initialize(new List<Entity>() { account, contact1, contact2, contact3 });

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.LinkEntities.Add(
                new LinkEntity()
                {
                    LinkFromEntityName = "contact",
                    LinkToEntityName = "account",
                    LinkFromAttributeName = "parentcustomerid",
                    LinkToAttributeName = "accountid",
                    JoinOperator = JoinOperator.Inner,
                    Columns = new ColumnSet(new string[] { "name" })
                }
            );
            qe.ColumnSet = new ColumnSet(new string[] { "fullname", "parentcustomerid" });

            var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe);

            Assert.True(result.Count() == 2);
            var firstContact = result.FirstOrDefault();
            var lastContact = result.LastOrDefault();

            Assert.True(firstContact["fullname"].Equals(contact1["fullname"]));
            Assert.True(lastContact["fullname"].Equals(contact2["fullname"]));
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:40,代码来源:FakeContextTestTranslateQueryExpression.cs

示例4: UpdateState

 private void UpdateState(bool touch, bool onlychange, OptionSetValue statusvalue, OptionSetValue statevalue, Entity record)
 {
     var currentstate = record.Contains("statecode") ? record["statecode"] : new OptionSetValue(-1);
     var currentstatus = record.Contains("statuscode") ? record["statuscode"] : new OptionSetValue(-1);
     if (touch)
     {
         statevalue = (OptionSetValue)currentstate;
         statusvalue = (OptionSetValue)currentstatus;
     }
     if (!onlychange || !ValuesEqual(currentstate, statevalue) || !ValuesEqual(currentstatus, statusvalue))
     {
         var req = new SetStateRequest()
         {
             EntityMoniker = record.ToEntityReference(),
             State = statevalue,
             Status = statusvalue
         };
         var resp = Service.Execute(req);
         if (record.Contains("statecode"))
         {
             record["statecode"] = statevalue;
         }
         else
         {
             record.Attributes.Add("statecode", statevalue);
         }
         if (record.Contains("statuscode"))
         {
             record["statuscode"] = statusvalue;
         }
         else
         {
             record.Attributes.Add("statuscode", statusvalue);
         }
     }
 }
开发者ID:rajyraman,项目名称:XrmToolBox.Plugins,代码行数:36,代码来源:MainControl.cs

示例5: SaveCRMSOLine

        private void SaveCRMSOLine(CRMConnection crm, string company, Entity crmso, DataRow linerow, Entity entity, bool create)
        {
            string soline_orderno = Convert.ToString(linerow["t$orno"]);		// Transection Type
            string soline_transaction_type = Convert.ToString(linerow["t$ttyp"]);		// Transection Type
            string soline_project_no = Convert.ToString(linerow["t$cprj"]);		// Project Number
            string soline_position = Convert.ToString(linerow["t$pono"]);		// Position Number
            string soline_sequence = Convert.ToString(linerow["t$sqnb"]);		// Sequence Number
            DateTime soline_release_date = (DateTime)linerow["t$rdta"];		// Release Date
            DateTime soline_order_date = (DateTime)linerow["t$odat"];		// Order Date
            DateTime soline_planned_delivery_date = (DateTime)linerow["t$ddta"];		// Planned Delivery Date
            DateTime soline_planned_receipt_date = (DateTime)linerow["t$prdt"];		// Planned Recipt Date
            DateTime soline_delivey_date = (DateTime)linerow["t$dldt"];		// Delivery Date
            string soline_tax_code = Convert.ToString(linerow["t$cvat"]);		// Tax Code
            decimal soline_cancelled = Convert.ToDecimal(linerow["t$clyn"]);		// Cancelled
            string soline_sold_to_bp = Convert.ToString(linerow["t$ofbp"]);		// Sold to BP
            string soline_ship_to_bp = Convert.ToString(linerow["t$stbp"]);		// Ship to BP
            decimal soline_order_line_text = (decimal)linerow["t$txta"];		// Order Line Text
            double soline_price = Convert.ToDouble(linerow["t$pric"]);		// Price
            double soline_quantity = Convert.ToDouble(linerow["t$oqua"]);		// Ordered Quantity
            double soline_amount = Convert.ToDouble(linerow["t$oamt"]);		// Amount
            double soline_discount_percent = Convert.ToDouble(linerow["t$disc$1"]);		// Line Discount (%)
            double soline_discount_amount = Convert.ToDouble(linerow["t$ldam$1"]);		// Discount Amount
            double soline_ordered_line_discount_amount = Convert.ToDouble(linerow["t$amld"]);		// Orde Line Discount Amount
            double soline_total_amount = Convert.ToDouble(linerow["t$oamt"]);		// Total Amount
            string soline_invoice = Convert.ToString(linerow["t$invn"]); // Invoice Number

            entity["am_name"] = soline_orderno;
            entity["am_lopsalesordernumberid"] = crmso.ToEntityReference();
            entity["am_txttransactiontype"] = soline_transaction_type;
            entity["am_txtprojectnumber"] = soline_project_no;
            entity["am_intpositionnumber"] = Convert.ToInt32(soline_position);
            entity["am_intsequencenumber"] = Convert.ToInt32(soline_sequence);
            entity["am_dtreleasedate"] = soline_release_date;
            entity["am_dtorderdate"] = soline_order_date;
            entity["am_dtplanneddeliverydate"] = soline_planned_delivery_date;
            entity["am_dtplannedreceiptdate"] = soline_planned_receipt_date;
            entity["am_dtdeliverydate"] = soline_delivey_date;
            entity["am_bittaxcode"] = (soline_tax_code.Trim() != "199");
            entity["am_bitcancelled"] = (soline_cancelled == 1);
            entity["am_lopsoldtobp"] = crm.FindRefByBaanCode(CRM.ENTITY_ACCOUNT, soline_sold_to_bp);
            entity["am_lopshiptobp"] = crm.FindRefByBaanCode(CRM.ENTITY_ACCOUNT, soline_ship_to_bp);
            entity["am_ntxtorderlinetext"] = BaanStorage.GetLookupString(company, soline_order_line_text);
            entity["am_floatprice"] = soline_price;
            entity["am_floatorderedquantity"] = soline_quantity;
            entity["am_floatamount"] = soline_amount;
            entity["am_floatlinediscount"] = soline_discount_percent;
            entity["am_floatdiscountamount"] = soline_discount_amount;
            entity["am_floatorderlinediscountamount"] = soline_ordered_line_discount_amount;
            entity["am_floattotalamount"] = soline_total_amount;
            entity["am_txtinvoicenumber"] = soline_invoice;

            if (create)
            {
                crm.service.Create(entity);
            }
            else
            {
                crm.service.Update(entity);
            }
        }
开发者ID:shiftright,项目名称:amtsync_b2c,代码行数:60,代码来源:ImportWorker.cs

示例6: XrmFakedContext

        public void When_executing_a_query_expression_with_simple_equals_condition_expression_returns_right_number_of_results_with_retrieve_multiple()
        {
            var context = new XrmFakedContext();
            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";
            var contact3 = new Entity("contact") { Id = Guid.NewGuid() }; contact3["fullname"] = "Contact 3"; contact3["firstname"] = "First 3";

            var account = new Entity("account") { Id = Guid.NewGuid() };
            account["name"] = "Account 1";

            contact1["parentcustomerid"] = account.ToEntityReference(); //Both contacts are related to the same account
            contact2["parentcustomerid"] = account.ToEntityReference();

            context.Initialize(new List<Entity>() { account, contact1, contact2, contact3 });

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.LinkEntities.Add(
                new LinkEntity()
                {
                    LinkFromEntityName = "contact",
                    LinkToEntityName = "account",
                    LinkFromAttributeName = "parentcustomerid",
                    LinkToAttributeName = "accountid",
                    JoinOperator = JoinOperator.Inner
                }
            );
            qe.ColumnSet = new ColumnSet(true);
            //Filter criteria
            qe.Criteria = new FilterExpression()
            {
                FilterOperator = LogicalOperator.And,
                Conditions =
                {
                    new ConditionExpression("fullname", ConditionOperator.Equal, "Contact 1")
                }
            };

            var service = context.GetFakedOrganizationService();
            var result = service.RetrieveMultiple(qe);

            Assert.True(result.Entities.Count == 1);
            var firstContact = result.Entities.FirstOrDefault();
            Assert.True(firstContact["fullname"].Equals("Contact 1"));
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:44,代码来源:FakeContextTestTranslateQueryExpression.cs

示例7: When_executing_a_query_expression_with_all_attributes_all_of_them_are_returned

        public void When_executing_a_query_expression_with_all_attributes_all_of_them_are_returned()
        {
            var context = new XrmFakedContext();
            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";
            var contact3 = new Entity("contact") { Id = Guid.NewGuid() }; contact3["fullname"] = "Contact 3"; contact3["firstname"] = "First 3";

            var account = new Entity("account") { Id = Guid.NewGuid() };
            account["name"] = "Account 1";

            contact1["parentcustomerid"] = account.ToEntityReference(); //Both contacts are related to the same account
            contact2["parentcustomerid"] = account.ToEntityReference();

            context.Initialize(new List<Entity>() { account, contact1, contact2, contact3 });

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.LinkEntities.Add(
                new LinkEntity()
                {
                    LinkFromEntityName = "contact",
                    LinkToEntityName = "account",
                    LinkFromAttributeName = "parentcustomerid",
                    LinkToAttributeName = "accountid",
                    JoinOperator = JoinOperator.Inner
                }
            );

            //We only select fullname and parentcustomerid, firstname should not be included
            qe.ColumnSet = new ColumnSet(true);

            var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe);

            Assert.True(result.Count() == 2);
            var firstContact = result.FirstOrDefault();
            var lastContact = result.LastOrDefault();

            //Contact 1 attributes = 4 + 5 (the extra five are the CreatedOn, ModifiedOn, CreatedBy, ModifiedBy + StateCode attributes generated automatically
            //+ Attributes from the join(account) = 2 + 5

            Assert.True(firstContact.Attributes.Count == 16);
            Assert.True(lastContact.Attributes.Count == 16);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:42,代码来源:FakeContextTestTranslateQueryExpression.cs

示例8: GetLocalCrmDatabaseOrganizationService

        private static IClientSideOrganizationService GetLocalCrmDatabaseOrganizationService(string organizationName, Guid impersonationUserId)
        {
            // Create a unique Database for each Unit Test by looking up the first method in the stack trace that has a TestMethodAttribute,
            // and using it's method handle, combined with the OrganizationName, as a unqiue Key
            var method = GetUnitTestMethod() ?? MethodBase.GetCurrentMethod();
            string databaseKey = String.Format("UnitTest {0}:{1}:{2}", method.Name, organizationName, method.MethodHandle);

            var info = LocalCrmDatabaseInfo.Create(TestSettings.EarlyBound.Assembly, TestSettings.EarlyBound.Namespace, databaseKey, impersonationUserId);

            var service = new LocalCrmDatabaseOrganizationService(info);

            // Create BU and SystemUser for currently executing user
            var bu = new Entity(BusinessUnit.EntityLogicalName)
            {
                [BusinessUnit.Fields.Name] = "Currently Executing BusinessUnit"
            };
            bu.Id = service.Create(bu);

            var id = service.Create(new Entity(SystemUser.EntityLogicalName)
            {
                [SystemUser.Fields.FirstName] = Environment.UserDomainName.Split('/').First(),
                [SystemUser.Fields.LastName] = Environment.UserName,
                [SystemUser.Fields.BusinessUnitId] = bu.ToEntityReference(),
            }.ToSdkEntity());

            info = LocalCrmDatabaseInfo.Create(TestSettings.EarlyBound.Assembly, TestSettings.EarlyBound.Namespace, databaseKey, id, impersonationUserId, bu.Id);

            return new LocalCrmDatabaseOrganizationService(info);
        }
开发者ID:gitter-badger,项目名称:XrmUnitTest,代码行数:29,代码来源:TestBase.cs

示例9: Should_Not_Fail_On_Conditions_In_Link_Entities

        public static void Should_Not_Fail_On_Conditions_In_Link_Entities()
        {
            var fakedContext = new XrmFakedContext();
            var fakedService = fakedContext.GetFakedOrganizationService();

            var testEntity1 = new Entity("entity1")
            {
                Attributes = new AttributeCollection
                {
                    {"entity1attr", "test1" }
                }
            };
            var testEntity2 = new Entity("entity2")
            {
                Attributes = new AttributeCollection
                {
                    {"entity2attr", "test2" }
                }
            };

            testEntity1.Id = fakedService.Create(testEntity1);
            testEntity2.Id = fakedService.Create(testEntity2);

            var testRelation = new XrmFakedRelationship
            {
                IntersectEntity = "TestIntersectEntity",
                Entity1LogicalName = "entity1",
                Entity1Attribute = "entity1attr",
                Entity2LogicalName = "entity2",
                Entity2Attribute = "entity2attr"
            };
            fakedContext.AddRelationship(testRelation.Entity2LogicalName, testRelation);
            fakedService.Associate(testEntity1.LogicalName, testEntity1.Id, new Relationship(testRelation.Entity2LogicalName), new EntityReferenceCollection { testEntity2.ToEntityReference() });

            var query = new QueryExpression
            {
                EntityName = "entity1",
                Criteria = new FilterExpression { FilterOperator = LogicalOperator.And },
                ColumnSet = new ColumnSet(true)
            };

            var link = new LinkEntity
            {
                JoinOperator = JoinOperator.Natural,
                LinkFromEntityName = "entity1",
                LinkFromAttributeName = "entity1attr",
                LinkToEntityName = "entity2",
                LinkToAttributeName = "entity2attr",
                LinkCriteria = new FilterExpression
                {
                    FilterOperator = LogicalOperator.And,
                    Conditions = { new ConditionExpression { AttributeName = "entity2attr", Operator = ConditionOperator.Equal, Values = { "test2" } } }
                }
            };
            query.LinkEntities.Add(link);

            var result = fakedService.RetrieveMultiple(query);
            Assert.NotEmpty(result.Entities);
            Assert.Equal(1, result.Entities.Count);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:60,代码来源:QueryLinkEntityTests.cs


注:本文中的System.Entity.ToEntityReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。