Member Avatar for lithium112

I built a database structure with codefirst EF from a tutorial but I can't find the database.

I've looked in (localdb) and it's not in my local install of SQLServer. Would anybody know where I would need to look to find the database?

Do you have a connection string?

Depends on what tutorial you've been following. You can code against an existing database (in which it's your job to create it) or you can code against a new database where your context will attempt to create the database when needed. In both cases, of course, you need something to host the database like SQL Server.

So...what tutorial are you following so we have a better idea of what your project looks like?

deceptikon - he says hes doing codefirst so the code will generate the database - where it does that depends on the connection string.

hes doing codefirst so the code will generate the database

That's an unwarranted assumption. Code first doesn't unconditionally generate a database; how you've defined your context specifies what EF does with the model to maintain database integrity.

where it does that depends on the connection string

Indeed, it does. But would you rather direct an apparently new programmer to the location of the connection string in a project that you haven't seen, or simply get a URL to the tutorial being followed so you have a reasonable expectation of what the project looks like? ;)

Sorry I'm confused. If a code first approach doesn't generate your database from your models then where does the database come from?

Just thought - are you talking bout manually creating an empty database and then using code first? In that case yes then code first is not actually creating the database as such, it is creating the database tables etc.

The connection string, which is almost certainly in a .config file is the easiest place to find the database though in my oppinion. I also suspect that the OP didn't create the database manually otherwise they would know where it is I would hope!

Member Avatar for lithium112

This is the tutorial I'm following: https://msdn.microsoft.com/en-us/data/jj193542

Also, Dave is correct, codefirst implies that you code first, then using EF it will create the database for you.

In that tutorial there is the following - does that help?

Where’s My Data?

By convention DbContext has created a database for you.
If a local SQL Express instance is available (installed by default with Visual Studio 2010) then Code First has created the database on that instance
If SQL Express isn’t available then Code First will try and use LocalDb (installed by default with Visual Studio 2012)

There is a link in there too on the actual page telling you about LocalDb.

Member Avatar for lithium112

I looked at those database connections, localdb and ssms. I don't have express. I also looked at the link provided. For some odd reason, I don't see it anywhere. I know it was created somewhere though since VS was doing work to get it set up. Unfortunately it didn't have anything in the console about where it put the database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.