2

Our build engineer has left for another company.

He's hand over his project to me. But I usually code not using EF, so I don't know something, his using Entity file like EntityDataModel.edmx contain all data.

I don't know how to connect to this. I usually connect to SQL Server by connectionString = ...etc. I also find this string in his application like:

<connectionStrings><add name="PCApp_TaxitechEntities" connectionString="metadata=res://*/EntityModel.EntityDataModel.csdl|res://*/EntityModel.EntityDataModel.ssdl|res://*/EntityModel.EntityDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SDDMS-010\SQLEXPRESS;initial catalog=PCApp_Taxitech;user id=sa;password=;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

2
  • 1
    Doesn't matter that much in this case, but in future take care that you do not include the password in your post ... Commented Apr 1, 2016 at 5:52
  • I'm forget this. Thanks your reminds. Commented Apr 1, 2016 at 6:31

3 Answers 3

3

The very first thing you should do upon being handed an existing project is to familiarize yourself with the major tools used in that project. You're not going to be very successful hacking away at a project based on a significant tool such as Entity Framework without investing some time to learn about that tool. Open up the project that contains the EntityDataModel.edmx file, look at the references, see what version of EntityFramework is being used, pick your favorite learning method (books, videos, blog posts, whatever), and dig in investing the hours needed to learn how to work with that tool.

But that's not the question you asked.

This section of the app.config file gives the clues you need:

data source=SDDMS-010\SQLEXPRESS;initial catalog=PCApp_Taxitech;user id=sa;password=(redacted);
  • You are looking for a database named PCApp_Taxitech
  • Hosted in Microsoft SQL Server Express (not a tool you're familiar with? Take some time to read up on it)
  • Hosted on a machine named SDDMS-010
  • You have the credentials to log in: user id = sa, password = (redacted)

If you have access to the machine SDDMS-010, then you're in business. You can open up the database in SQL Server Management Studio (Server name: SDDMS-010\SQLEXPRESS, Authentication: SQL Server Authentication, User name: sa, Password: (redacted)) and begin looking around.

If you don't have access to that machine, Entity Framework can create the database for you.

  1. Install SQL Server Express

  2. Find the project containing the EntityModel.edmx file, open the app.config, and edit the connection string. Set the data source, user id, and password to match the SQL Express instance you installed.

  3. Double-click the EntityModel.edmx file in Visual Studio. You should see an entity model diagram.

  4. Right-click in the empty space somewhere on the diagram. Select "Generate database from model", and click through the options in the dialog that comes up.

  5. Once Visual Studio finishes creating the database, you can now use SQL Server Management Studio to connect to your newly installed database instance and begin poking around in your database.

  6. If your database requires some seed data, you may need to get some project-specific information on how to properly fill in that seed data in your new database.

So that will get you a database to poke around in using SSMS. As far as connecting from code, you're quickly going to run out of luck without familiarizing yourself with Entity Framework first. In general, though, it goes something like this:

  1. If the .edmx file is in a separate project than your executable, you may need to edit the app.config file in your executable's project. Set the data source, initial catalog, user id, and password to match your database.

  2. Under the EntityModel.edmx file, look for a file that ends with .Context.tt. under that file, look for a file that ends with .Context.cs. Open up that file.

  3. Look for a class derived from DbContext.

  4. Create an instance of that class, and use Linq queries to access that data provided by that class.

For example, your class may look something like this:

public partial class MyDataContext : DbContext
{
    public MyDataContext()
        : base("name=MyDataContext")

    public virtual DbSet<MyEntity> MyEntities { get; set; }
}

You would be able to select all of the MyEntities using this code:

var context = new MyDataContext();
var data = from e in context.MyEntities
           select e;
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer in great detail and very useful for me. Thank you very much.
3

Edmx does not contain any data, it is just model definition file. It defines storage model (database schema), conceptual model (your classes) and how they map to each other.

Data are still stored in underlaying DBMS. In your case, database should be located on machine named SDDMS-010 running instance of MS SqL Server named SQLEXPRESS and database named PCApp_Taxitech. So you should have access to that database first.

If you don't care about data you can generate storage from conceptual model:

https://msdn.microsoft.com/en-us/library/dd456815(v=vs.100).aspx

1 Comment

I don't have file database, like .mdf? I must create a new database base on Edmx file? Or any method speed fast? Thanks.
2

Once you get past the metadata attribute (which is just a pipe delimited list of resources for metadata and mapping), it is a regular connection string. In the app there might be code similar to:

var db = new EntityModel("PCApp_TaxitechEntities"); 

This is opening the connection to the db

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.