Link to home
Start Free TrialLog in
Avatar of wpeterb
wpeterb

asked on

Help with Lambda query syntax

I am trying to validate a unique combination of data in a table. I am using
devart Entity Framework.

I am trying to setup the validation on entity with Lightswitch as the application.

The Table I am checking for values already existing is:  StuntDetails.
It has a foreign key for packageID and StuntId.   I want to check that the
combination of PackageID and StuntID do not already exist in StuntDetails when
inserting.  If it does, I want to raise an error.

In Entity Framework, it makes the foreign key and object linked to the parent table and for
referencing my PackageID I have to enter the entity  Package.PackageId.

Can you please help me figure this out so it works correctly?

Here is what I have coded but I don't have the lambda code correct:

            if (this.StuntDetails.Where(x => x.Package.PackageId == entity.Package.PackageId).FirstOrDefault() && x.Stunt.StuntId == entity.Stunt.StuntId).FirstOrDefault())
            {
                results.AddPropertyError(
                    "This PackageId has already been entered for this Stunt. PackageId and StuntId must be unique for Stunt Detail.",
                    entity.Details.Properties.StuntDetailId);
            }

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial