I walk past Scott Hanselman's book on how to create a NerdDinner MVC application.
To check the type of entity of the type that was generated by the master of the entity data model, he first expanded the entity of the object using the partial trick method, and then created a friend class to communicate with the Dinner.
See the following code for more details.
using System.ComponentModel.DataAnnotations;
namespace NerdDinner.Models
{
[MetadataType(typeof(DinnerValidation))]
public partial class Dinner { }
public class DinnerValidation
{
[Required(ErrorMessage = "Title is required")]
[StringLength(50, ErrorMessage = "Title may not be longer than 50 characters")]
public string Title { get; set; }
[Required(ErrorMessage = "Description is required")]
[StringLength(256, ErrorMessage = "Description may not be longer than 256 characters")]
public string Description { get; set; }
[Required(ErrorMessage = "Addresss is required")]
public string Address { get; set; }
[Required(ErrorMessage = "Country is required")]
public string Country { get; set; }
[Required(ErrorMessage = "Contact phone is required")]
public string ContactPhone { get; set; }
}
}
My question
Is there a “convenient” way to create and associate a buddy class with Dinner? I mean, we can use the tool in Visual Studio or any plug-in to create a buddy class and automatically associate a buddy with Dinner. Of course, I have to make some adjustments to the generated code according to my needs, but this is not a big problem.
1:
. , . , DinnerId Int32, DinnerID, int.