DB and EF Flashcards
In Entity Framework, when you use .Add on a context that has foreign keys to another context what happens to the state of these contexts?
The state of BOTH of these gets marked as “Added”
If you get the following error, linked to a Entity Framework issue, what is most likely solution?
{“The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.”}
You’ve forgotten to use an .Include on the LINQ query to pull in the foreign key table
If a new database has been added or changes have been made to the schema, what will you need to do?
rebuild your local database
In PowerShell run:
.\packages\psake.4.3.2\tools\psake.ps1 RebuildDatabase
What does the N in the follow statement do? SELECT 1 FROM sys.objects WHERE name = N’John’
It acts similar to an @ in C#, telling the complier we’re going to be dealing with a nvarchar string
What does ‘ON [PRIMARY]’ do in the following: CREATE TABLE dbo.Authoriser ( Id int IDENTITY(1,1) NOT NULL, Name nvarchar(100) NOT NULL, Title nvarchar(100) NULL, UpdatedBy nvarchar(50) NOT NULL DEFAULT SUSER_SNAME(), UpdatedDateTime datetime NOT NULL DEFAULT GETDATE(), RowVersion rowversion NOT NULL, CONSTRAINT [PK_Authoriser] PRIMARY KEY (Id) ) ON [PRIMARY]
When you create a database in Microsoft SQL Server you can have multiple file groups, where storage is created in multiple places, directories or disks. Each file group can be named. The PRIMARY file group is the default one, which is always created, and so the SQL you’ve given creates your table ON the PRIMARY file group.
What does the following do and why is it so important?
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove();
}
It stops EF from automatcially adding an ‘s’ to the end of your DbSet names.
So if you had a table in your DB called Contact, and a DB Set with the same name, EF would automatically try and find a table called ‘Contacts’ if you didn’t add this line into the model creater
In SQL Objects, what is U?
Table (user defined)
In SQL Objects, what is PK?
Primary Key
In SQL Objects, what is FK?
Foreign Key