1

我是 Entity Framework 的新手,并试图了解如何在 ASP.Net MVC 4 应用程序中执行此操作。

我有一个约会对象,其中包含一个客户对象(客户信息)和约会的日期时间。我似乎无法弄清楚如何正确存储客户对象。

看我现在做事的方式我想我应该存储客户ID,但我不知道以后如何检索客户信息(我使用模型吗?另一个域类“AppointmentDetails”?我应该使用服务层对象?)

   public class Appointment
    {
        public int Id { get; set; }
        public Customer Customer { get; set; }
        public DateTime AppointmentDateTime { get; set; }

        public Appointment()
        {

        }

        public Appointment(Customer customer, DateTime appointmentDateTime)
        {
            Customer = customer;
            AppointmentDateTime = appointmentDateTime;
        }
    }

客户.cs

   public class Customer
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Province { get; set; }
        public string Phone { get; set; }
        public string Email { get; set; }

        public Customer()
        {

        }

        public Customer(string firstName, string lastName, string address, string city, string province, string phone, string email)
        {
            FirstName = firstName;
            LastName = lastName;
            Address = address;
            City = city;
            Province = province;
            Phone = phone;
            Email = email;
        }
    }
4

1 回答 1

0

到目前为止,我一直按照 DB 优先方法使用实体框架,但我相信您的类应该存储如下内容:

public virtual ICollection<Appointment> Appointment{ get; set; } // which will be used to access your Customer's appointments.

在您的客户课程中,而在您的约会课程中,您将拥有:

public int CustomerId { get; set; }
public virtual Customer Customer { get; set; }

你是如何创建这些课程的?如果您使用模型设计器,它会生成必要的属性来连接您的类。

于 2013-08-30T07:59:00.287 回答