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())
                    "This PackageId has already been entered for this Stunt. PackageId and StuntId must be unique for Stunt Detail.",

Thank you!
Who is Participating?
Ioannis ParaskevopoulosConnect With a Mentor Commented:

It should be

            if (this.StuntDetails.Any(x => x.Package.PackageId == entity.Package.PackageId && x.Stunt.StuntId == entity.Stunt.StuntId))

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.