开发者

LightSwitch - Business Rules

I have a Master/Detail screen in LightSwitch. I allow user to delete details' items. However, the user i开发者_开发问答s allowed to delete all except one. In other words,only one detail item needs to be present.

Is this doable in lightswitch?

Regards


Here's how to do this:

  1. Open the entity for which you want to restrict the delete operation in the LightSwitch designer
  2. Using the Write Code drop-down, create an Entity_Deleting event
  3. In the deleting event, check the count of detail items for the master entity. If it is 0 discard the changes.

Here's how to code this. In this example, the master entity is AdAgreement, and the detail entity is Issues:

partial void Issues_Deleting(Issue entity)
{
    if (entity.Details.EntityState == EntityState.Deleted 
            && entity.AdAgreement.Issues.Count() == 0)
    {
        entity.Details.DiscardChanges();
    }
}

Unfortunately you can't perform this check in the Entity_CanDelete event, which would give you a better user experience, in my opinion. The problem is that CanDelete operates at the entity set level, and there is no access to the individual entity that would be deleted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜