PrimaryContext myContext = new PrimaryContext();EmailModel emailAccount = myContext.EmailModel.Where(x => x.Email == "someone@someone.com").First();
If there are no items to retrieve into the declared emailAccount you will receive an InvalidOperationException with details of "Sequence contains no elements".
To resolve this, use .FirstOrDefault() instead of .First(). This will give you the actual model or null if the condition is not found.
EmailModel emailAccount = myContext.EmailModel.Where(x => x.Email == "someone@someone.com").FirstOrDefault();
0 comments:
Post a Comment