Wednesday, September 19, 2018

Entity Framework Count not raising exception

Leave a Comment

I'm using LINQ to return a count of items from Entity Framework. I've noticed, however, that despite an invalid DSN being set, I'm not getting an exception raised, simply a 0 return value.

So, I've overridden my database context like this to pass in a DSN:

public partial class MissingDetails : DbContext {     public MissingDetails(string DSN) : base(DSN)         //: base("name=MissingDetails")     {     } 

I then call it:

        public int ImportCount         {             get             {                 dbContext = new MissingDetails(suppliedDSN);                 return dbContext.Details.Count(                     i => (                         (i.UniqueGroupReference == uniqueIdentifier) &&                         (i.UniqueGroupReferenceSubGroup == subIdentifier)                         )                     );             }         } 

All works fine when I supply a valid DSN, but if I give it something invalid it just returns 0 rather than an exception. Is this as expected?

btw, I'm targetting .Net 4.0 so using Entity Framework 6.2.0

thanks.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment