相关活动记录

发布于 12-21 22:46 字数 1959 浏览 2 评论 0原文

所以事情是这样的:我创建了一个自定义实体“new_ligneContrat”,它具有一对多 与另一个自定义实体“new_produit”的关系。

目标是:当创建“new_ligneContrat”的新记录时,它必须获取之前“new_ligneContrat”的“new_produit”记录。该插件是基于“new_ligneContrat”构建的。

我想知道 FetchExpression + last() 是否可以做到这一点,但现在我还没有找到合适的解决方案...

提前致谢!

编辑1:我们决定为了建立 to n 关系,所以我做了以下事情:

QueryExpression query = new QueryExpression();
 query.EntityName = "new_produit";
                    query.ColumnSet = new ColumnSet("new_produitid");
                    关系关系=newRelationship();

                    关系.SchemaName =“new_new_lignecontrat_new_produit”;
                    关系查询集合相关实体=新的关系查询集合();
                    relatedEntity.Add(关系,查询);
                    RetrieveRequest 请求 = new RetrieveRequest();
                    request.RelatedEntitiesQuery = relatedEntity;
                    request.ColumnSet = new ColumnSet("new_lignecontratid");
                    request.Target = 新的 EntityReference
                    {
                        Id = 第一个.Id,
                        逻辑名称 = 第一个.逻辑名称

                    };

                    RetrieveResponse 响应 = (RetrieveResponse)service.Execute(request);
    if (((DataCollection<Relationship, EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new
> Relationship("new_new_lignecontrat_new_produit")) &&
> ((DataCollection<Relationship,
> EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new
> Relationship("new_new_lignecontrat_new_produit")].Entities.Count > 0)
>                         {
>                             response.Results.Remove("new_produitid");
>                             response["new_lignecontratid"] = new EntityReference(target.LogicalName, target.Id);

这是正确的吗?

So here is the thing : I created a custom entity "new_ligneContrat" which has a one-to-many
relationship with another custom entity "new_produit".

Here is the goal: when a new record of "new_ligneContrat" is created, it has to get the "new_produit" records of the "new_ligneContrat" before it. The plugin is built on "new_ligneContrat.

I was wondering if FetchExpression + last() could do it, but right now I haven't found the proper solution...

Thanks in advance !

Edit1 : We decided to go for a n to n relationship, so I did the following:

QueryExpression query = new QueryExpression();
                    query.EntityName = "new_produit";
                    query.ColumnSet = new ColumnSet("new_produitid");
                    Relationship relationship = new Relationship();

                    relationship.SchemaName = "new_new_lignecontrat_new_produit";
                    RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
                    relatedEntity.Add(relationship, query);
                    RetrieveRequest request = new RetrieveRequest();
                    request.RelatedEntitiesQuery = relatedEntity;
                    request.ColumnSet = new ColumnSet("new_lignecontratid");
                    request.Target = new EntityReference
                    {
                        Id = first.Id,
                        LogicalName = first.LogicalName

                    };

                    RetrieveResponse response = (RetrieveResponse)service.Execute(request);
    if (((DataCollection<Relationship, EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new
> Relationship("new_new_lignecontrat_new_produit")) &&
> ((DataCollection<Relationship,
> EntityCollection>)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new
> Relationship("new_new_lignecontrat_new_produit")].Entities.Count > 0)
>                         {
>                             response.Results.Remove("new_produitid");
>                             response["new_lignecontratid"] = new EntityReference(target.LogicalName, target.Id);

Is that correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

跨年2024-12-28 22:46:20

根据插件运行的插件执行阶段(验证前、操作前/操作后),一种选择是执行依赖于当前时间或 CreatedOn 属性的 LINQ 查询新的 new_ligneContrat 记录并调用 First 方法来获取最新的 new_produit 记录。我在下面添加了一个模型。

DateTime d = DateTime.Now;
// or...DateTime d = targetEntity.Attributes["CreatedOn"].Value;

var usersSettings = (from lc in osc.CreateQuery<new_ligneContrat>()
                    join p in osc.CreateQuery<new_produit>() on lc.new_produitId equals p.new_produitId.Id
                    where lc.CreatedOn < d
                    orderby lc.CreatedOn descending
                    select p).First();

Depending on which stage of the plugin execution your plugin is running in (pre-validation, pre/post-operation), one option is to execute a LINQ query that's dependent on the current time or the CreatedOn property of the new new_ligneContrat record and call the First method to get the latest new_produit record. I've included a mockup below.

DateTime d = DateTime.Now;
// or...DateTime d = targetEntity.Attributes["CreatedOn"].Value;

var usersSettings = (from lc in osc.CreateQuery<new_ligneContrat>()
                    join p in osc.CreateQuery<new_produit>() on lc.new_produitId equals p.new_produitId.Id
                    where lc.CreatedOn < d
                    orderby lc.CreatedOn descending
                    select p).First();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文