0

Trying to select value from a empty records:

 var id = (from transactions in testTransactions.Transactions
                                      orderby transactions.TransID descending select transactions.TransID).First();

How can I give a default value then the table is empty.

Thnak you.

2 Answers 2

1

You can try this using first or default if the item is not there at all it would give null

    var id = (from transactions in testTransactions.Transactions
                                          orderby transactions.TransID descending select transactions.TransID).FirstOrDefault();
if(id!=null)
{


}
Sign up to request clarification or add additional context in comments.

1 Comment

@Kelvin Fixx you have to check first if the value is null like above
0

If you have error before line IF than, maybe you must check you class testTransaction and add to all filed which can be null something like this

public string? MyVal{get;set;}

But if you use EF designer they must create all types automatically and you must change something else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.