0

I need to validate a Parameter if it contains any values before I delete it. The Parameter is in another table and values are in another table. I am trying this by using lambda expression, but just can't find the right way. This gets the data from CalculationParameters table:

Factory.Definitions.CalculationParameters.List(); // List() lists all the data.

And this gets the data from CalculationParametersValues table:

Factory.Definitions.CalculationParametersValues.List(); // List() lists all the data.

Now if the "Id" (from CalculationParameter) equals to "CalculationParameterId" (from CalculationParametersValue) means that CalculationParameter contains values and I can't delete it.

Does anyone have any idea to help me out here ?

4

2 回答 2

0

I understand that you want to remove all the CalculationParameters that have no records in CalculationParametersValues. If so, try something like this :

CalculationParameters.RemoveAll(p=> !(CalculationParametersValues.select(c=> c.CalculationParameterId)).contains(p.CalculationParameterId))
于 2013-05-02T13:49:42.153 回答
0

如果我知道您想检查 CalculationParameters 中的 ID 是否存在于 CalculationParametersValues 中

你可以试试这个

bool exist =Factory.Definitions.CalculationParameters.List()
            .Any(a=> Factory.Definitions.CalculationParametersValues.List().Any(b=>b.Id ==a.Id))
于 2013-05-02T13:29:22.380 回答