DB and EF Flashcards

1
Q

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?

A

The state of BOTH of these gets marked as “Added”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.”}

A

You’ve forgotten to use an .Include on the LINQ query to pull in the foreign key table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If a new database has been added or changes have been made to the schema, what will you need to do?

A

rebuild your local database

In PowerShell run:

.\packages\psake.4.3.2\tools\psake.ps1 RebuildDatabase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the N in the follow statement do? SELECT 1 FROM sys.objects WHERE name = N’John’

A

It acts similar to an @ in C#, telling the complier we’re going to be dealing with a nvarchar string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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]

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the following do and why is it so important?

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

modelBuilder.Conventions.Remove();

}

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In SQL Objects, what is U?

A

Table (user defined)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In SQL Objects, what is PK?

A

Primary Key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In SQL Objects, what is FK?

A

Foreign Key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly