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!
wpeterbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ioannis ParaskevopoulosCommented:
Hi,

It should be

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

Open in new window


Giannis
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.