0

my project use ef and reposiroty for communication with database

when i find a record with the id

 var applicant = applicantProvider.Get(1020);    

 Context.Set<TEntity>().Find(id);

then i got exception

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Year, Month, and Day parameters describe an un-representable DateTime.

the data record is :

id DOB SubmitDate CreateDate UpdateDate

1020 01/06/1949 2010-05-12 16:01:39 2010-05-14 16:59:10 2011-05-28 10:22:00

i don't know how i got that error pls help me

My entity Applicant

public class ABGApplicant

public int ABGApplicantID { get; set; }
public DateTime? DOB { get; set; }
public DateTime? SubmitDate { get; set; }
public DateTime? CreateDate { get; set; }
public DateTime? UpdateDate{ get; set; }

this is my main function

IABGApplicantProvider applicantProvider = new ABGApplicantProvider(new GenesisContext());

            var applicant = applicantProvider.Get(1020);

this is my ABGApplicantProvider extend repository

public class ABGApplicantProvider : Repository<ABGApplicant>, IABGApplicantProvider
    {
        public ABGApplicantProvider(DbContext context) : base(context)
        {
        }
    }

This is class Repository

public class Repository<TEntity> : IRepository<TEntity> where TEntity : class

public TEntity Get(int id)
        {
            // Here we are working with a DbContext, not PlutoContext. So we don't have DbSets 
            // such as Courses or Authors, and we need to use the generic Set() method to access them.
            return Context.Set<TEntity>().Find(id);
        }

enter image description here

7
  • is possible you're passing not an int or string or guid but a Datetime in your function Find(id)..so your id is a datetime? Commented Jan 6, 2017 at 11:13
  • No my id is number just want to find by id var applicant = applicantProvider.Get(1020); Commented Jan 6, 2017 at 11:18
  • can you post your POCO? your TEntity Commented Jan 6, 2017 at 11:19
  • i Updated my question Commented Jan 6, 2017 at 11:31
  • ok ..i'm pretty sure you've a dirty record in your db .. in the field maybe DOB ..can you check on Db ..in the record with id=1020 ..if is there something strange? Commented Jan 6, 2017 at 11:35

1 Answer 1

1

I think your problem is not in your repository but in the data inside your DB...

Check the record with id=1020 and then check the column DOB

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

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.