Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:31:08+00:00 2026-05-28T05:31:08+00:00

I am learning EF Code First from Programming Entity Framework Code First. The following

  • 0

I am learning EF Code First from “Programming Entity Framework Code First”. The following code snippets are copied from page 5 to page 7.

Visit.cs

using System;

namespace ChapterOne
{
    class Visit
    {
        public int Id { get; set; }
        public DateTime Date { get; set; }
        public String ReasonForVisit { get; set; }
        public String Outcome { get; set; }
        public Decimal Weight { get; set; }
        public int PatientId { get; set; }
    }
}

AnimalType.cs

namespace ChapterOne
{
    class AnimalType
    {
        public int Id { get; set; }
        public string TypeName { get; set; }
    }
}

Patient.cs

using System;
using System.Collections.Generic;

namespace ChapterOne
{
    class Patient
    {
        public Patient()
        {
            Visits = new List<Visit>();
        }
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime BirthDate { get; set; }
        public AnimalType AnimalType { get; set; }
        public DateTime FirstVisit { get; set; }
        public List<Visit> Visits { get; set; }
    }
}

VetContext.cs

using System.Data.Entity;

namespace ChapterOne
{
    class VetContext : DbContext
    {
        public DbSet<Patient> Patients { get; set; }
        public DbSet<Visit> Visits { get; set; }
    }
}

Program.cs

using System;
using System.Collections.Generic;

namespace ChapterOne
{
    class Program
    {
        static void Main(string[] args)
        {
            var dog = new AnimalType { TypeName = "Dog" };

            var patient = new Patient
            {
                Name = "Simpson",
                BirthDate = new DateTime(2008, 1, 28),
                AnimalType = dog,
                Visits = new List<Visit> 
                { 
                    new Visit 
                    { 
                        Date = new DateTime(2011, 9, 1)
                    }
                }

            };

            using (var context = new VetContext())
            {
                context.Patients.Add(patient);
                context.SaveChanges();
            }
        }
    }
}

Unfortunately, I got the following error. Could you tell me what is wrong?

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:31:08+00:00Added an answer on May 28, 2026 at 5:31 am

    Probably you’re not filling all required fields. The one i noticed is Patient.FirstVisit default value is not acceptable by sql server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning ASP.NET MVC and Entity Framework Code First, LINQ by creating a
I'm currently learning game programming using a framework called libgdx. It allows users to
I am learning some COM code and the following code puzzled me. STDMETHODIMP _(ULONG)
I'm a beginner to C programming. I'm trying to learning how to code a
This is a code snippet from O'Reilly Learning Opencv, cvNamedWindow(Example3, CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]);
I am learning PHP PEAR and testing the following code. However when I login,
I'm learning about deadlocks in Java, and there's this sample code from Sun's official
I just began learning network programming. My first program is very simple: once connected,
Noobie so bear with me. I've have been following the O'Rielyy Learning iPhone Programming
Code Taken From: Bytes to Binary in C Credit: BSchlinker The following code I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.