Entity Structure and Various Environments (Dev / Production)

I recently embarked on a new project using ASP.NET MVC, and I am not very familiar with this technology. I am still in a very early stage, and I am going to start learning how to use the Entity Framework to work with my data access code. I just have a rather difficult time doing the heads or tails of what the software / tool / function can do, but I think I'm on the right track with EF.

I am looking for something that will allow me to see the differences in my local database in my production database (the schema, not the actual data in it), and be able to publish it to SQL Server on our local network. In my opinion, I think of it as DVCS for databases.

Traditionally (for example, as I would say) I would write my own data access code using SQL in my code or stored procedures, etc., and I myself would deal with the database. This is no longer an option for me, because I need to set up separate environments for development and production, and I don’t have the time and desire to manually write all this code. Dev will be local to the dev machine, and production will be hosted on a server on our local network.

I recently started using the Publish feature in Visual Studio, and I was able to establish that it works very well by posting new versions in the directory that my IIS server is looking to serve the site.

I use Git and Sourcetree to work with DVCS for my project code, however I have never personally used or found a solution to do something similar for a database. At first it seemed to me that I was looking for some DVCS for SQL Server, but it did not bring much. Essentially, I just want some kind of tool that will manage version differences between local and production databases, and I think this is what EF can do for me.

SQL Server. , , EF . , EF SQL Server, , , , , Visual Studio. db SSMS, , SSMS, , EF .

  • , Entity Framework, ? , , ? , , / .. - , , , ...
  • , - , , , . , , , , .

, "" , .

+4
2

, , .

DbContext ( app.config web.config ) SQL, .

, DbContext, :

public YourModelContainer() : base("name=YourModelContainer")
{
}

, ( "name=..." ) .

, :

public YourModelContainer(string connectionString) : base(connectionString)
{
  // where connection string includes the metadata section
  // metadata=res://*/Models.YourModel.csdl|res://*/Models.YourModel.ssdl|res://*/Models.YourModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=YourDatabase;user id=dev;password=p455w0rd;MultipleActiveResultSets=True;App=EntityFramework"
  // This is just a concatenation of the metadata with a SQL connection string, you can use the EntityConnectionStringBuilder class if you're building this manually at runtime
}

. fooobar.com/questions/1196124/...

+1

Source: https://habr.com/ru/post/1622860/


All Articles