Saving data to database using Entity Framework

时间:2018-05-06 17:17:01

标签: c# asp.net-mvc entity-framework

I have made method randomArticlesPair.put(FirebaseConstants.RANDOM_ARTICLES_PAIR,"plain old string"); in data want; infile datalines dlm=' ,' ; informat var1 var2 var3 var4 $60.; input var1 $ var2 $ var3 $ var4 $; datalines; 832783_9399 973299,03200 238003 ; class for saving data to database hosted on Azure.

SaveRecord

Then I call this method in CurrentMovie.

public class CurrentMovie
{
    public int ID { get; set; }
    public string title { get; set; }
    public Nullable<int> release { get; set; }
    public string image { get; set; }

    public void SaveRecord(int? ID, string title, Nullable<int> release, string image)
    {
            var context = new movie_generationsEntities();
            var movie_record = new movie_generations();

            ID = movie_record.movieID;
            title = movie_record.title;
            release = movie_record.release;
            image = movie_record.image;              

            context.movie_generations.Add(movie_record);
            context.SaveChanges();                                       
    }
}

I am certain that data are saved in controller properties because I save them to var movieDB = new CurrentMovie(); movieDB.SaveRecord(movieDB.ID, movieDB.title, movieDB.release, movieDB.image); and successfully display them. Connection to the database is successful because it just saves empty rows with no expected data.

Is there something wrong or am I missing something? Thanks!

2 个答案:

答案 0 :(得分:0)

您创建一个新的CurrentMovie对象并在设置其属性之前保存它,显然,它的所有属性都等于其类型的默认值。

答案 1 :(得分:0)

当您想要完全相反时,您将新对象的值分配给参数。此外,您不需要在您的班级中使用这些属性。

您的代码应如下所示:

var librarianDataRow=$(this).closest('tr');
        var librarianName=librarianDataRow.find('td:eq(1)').text();