Chapter 2: Your First Entity Framework Application

Q1. DbSet<T> is the class you should be using to define a property in your context class that corresponds to a table in your database. The type parameter T represents a class that defines that table's structure in terms of .NET.

Q2. As DbContext holds an underlying connection to the database, you should utilize the IDisposable pattern and call Dispose on your context when you are done using it. You can also use the Using keyword to achieve the same.

Q3. The Find method can be used to locate a row in the database. It takes one or more parameters corresponding to the values of the primary key. If you have a single column that defines the primary key, only one value is needed. Multiple parameter values are reserved for tables with complex multicolumn primary keys.

Q4. You can use the Remove method and pass in an instance you would like to be deleted from the database when SaveChanges is called on your context.

Q5. You can just find the corresponding object and set its LastName property to new values. Then, you can call SaveChanges to commit the updated data to the database. You can use the Find method or LINQ to locate the matching row in the database. We will see other methods to issue updates in later chapters.

Q6. You will get an exception because no initializer is used. We will see in later chapters how migrations solve this problem.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.96.86