开发者

Generated Entity Framework Code

The code that gets generated by Entity Framework 4--mainly the AddTo and Create methods--should I be using those directly? I'm trying to understand the Create method. The CreateDinner method (in NerdDinner) for example is this:

public static Dinner CreateDinner(global::System.Int32 dinnerID, global::System.String title, global::System.DateTime eventDate, global::System.String description, global::System.String hostedBy, global::System.String contactPhone, global::System.String address, global::System.String country, global::System.Double latitude, global::System.Double longitude)
    {
        Dinner dinner = new Dinner();
        dinn开发者_JAVA百科er.DinnerID = dinnerID;
        dinner.Title = title;
        dinner.EventDate = eventDate;
        dinner.Description = description;
        dinner.HostedBy = hostedBy;
        dinner.ContactPhone = contactPhone;
        dinner.Address = address;
        dinner.Country = country;
        dinner.Latitude = latitude;
        dinner.Longitude = longitude;
        return dinner;
    }

There is no SubmitChanges() and when I view references, this method isn't being called anywhere. What's the purpose of this method?


Entity Framework default code generation template creates a Factory Method for each entity object in your Model. This static method lets you quickly create a new entity and the parameter list for it consists of all of the non-nullable properties in your class (and not all of them).
Therefore, it's not meant to Save or Submit anything to the DB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜