Where are my DataModel classes after added ADO.NET Entity Data Model - c#

Ok after finally getting the correct connection string to create the Mdf file in the App_Data folder. I tried to add a ADO.NET Entity Data Model to the Models folder following the tutorial in "Beginnning ASP.NET MVC 4".
However once added I should have being able to expand the DataModel.edmx to show the model classes, all thats showing is the DataModel.Designer.cs .
Has anyone come across this before ?
Also should I also be seeing this database in my SQL Express ?
Visual studio 2010, windows xp machie
Original Connection string, in case it helps...
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=HaveYouSeenMe;AttachDbFilename=|DataDirectory|HaveYouSeenMe.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
Connection string added when created ADO.NET Entity Data Model.
<add name="EntitiesConnection" connectionString="metadata=res://*/Models.DataModel.csdl|res://*/Models.DataModel.ssdl|res://*/Models.DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\HaveYouSeenMe.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>

open your EDMX and in Properties Window change Code generation strategy to Default and save your EDMX file
Update
Check out following link for more details
Database First Approach in Entity Framework

Related

attempt to open un named db failed. file with the same name exists, or it is located on UNC share

Actually i get a project from another pc and it has a database using local db having database with visual studio. before that i always used sql server for database. so i got stuck in it.
<add name="FZDatabase" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Talha\Desktop\Fashionzonefyp\Fashionzonefyp\App_DataFZDATABASE.MDF;Integrated Security=True" providerName="System.Data.SqlClient" />
here is the connection string. help as a totally new comer. any further suggestions and guidlines are also wellcomed... :)
Try this:
<add name="FZDatabase" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=C:\Users\Talha\Desktop\Fashionzonefyp\Fashionzonefyp\App_DataFZDATABASE.MDF;Integrated Security=True" providerName="System.Data.SqlClient" />
Actually there was a problem with my db name in connection string. and secondly my db was not in the directory of local db's which is by default (C:\Users\"Your pc name"\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB). thanks for help. :)

An error while trying to add a scaffolding controller in ASP.NET MVC with Entity model

I have an ASP.NET MVC 5 project with ADO.NET Entity Model (Model first approach). But when I'm trying to add a new "MVC 5 controller with views, using Entity Framework" I get that error:
There was an error running the selected code generator:
'Object reference not set to an instance of an object'
I've created a project using that tutorial.
There is one thing that is different from the tutorial: I use Windows authentication instead of SQL server authentication.
Connection strings in the web.config:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication4-20170527013424.mdf;Initial Catalog=aspnet-WebApplication4-20170527013424;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="TestContainer" connectionString="metadata=res://*/Models.Test.csdl|res://*/Models.Test.ssdl|res://*/Models.Test.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=Test123;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I've already tried to rebuild the project and reinstall MvcScaffolding.
Any help is much appreciated!
EDIT: Apparently it's working with the ApplicationDbContext(which is default connection string), but not with the Entity Model Container.

Use Azure Database (ASP.NET MVC)

I'm new in ASP.NET Development
I create MVC Project and as I understood it creates with default .mdf database.
I working with it and all was great, but I think about deploying app to azure.
So I need to use azure database.
I create it , all ok.
I read article how connect to azure db.
As I understood , I need connection string
Here it is
Server=tcp:smartsolutionsserver.database.windows.net,1433;Initial Catalog=smartdatabase;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
As I understood I need to paste it to Web.Release.config
I do this, so now it have look like this
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=tcp:smartsolutionsserver.database.windows.net,1433;Initial Catalog=smartdatabase;Persist Security Info=False;User ID=*********;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
But as I understood .mdf database connections wrote in Web.config file
And looks like this
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-SmartSolutions-20170124034333.mdf;Initial Catalog=aspnet-SmartSolutions-20170124034333;Integrated Security=True" providerName="System.Data.SqlClient" />
Tell me, how I can connect to azure database and use it instead of local .mdf database?
Thank's so much for help.
UPDATE
I try to add 2 new tables and publish app. After connecting to database from SQL Server Object Explorer, I see that tables added.
But when I try to register new user I see this
On local all ok
Screen
So my error was in The model backing the 'ApplicationDbContext' context has changed since the database was created
I go to table __MigrationHistory and delete row. After that, all okay. All works
# juunas Thank's for advice. I do this and see error. Also it can visible if you use IIS Console

.mdf file missing under the App_Data folder in ASP.NET MVC

I was following the tutorial on creating the Code First Entity Framework model on Asp.NET MVC Application from this tutorial.
As I proceeded, a file with the .mdf extension should have been generated under the App_Data folder in my project (in the solution explorer section). Currently this folder is empty.
I have tried building the project and cleaning it. Moreover I have enabled Show All Files option in the folder. I even did a refresh. The Entity Framework works just fine and is able to connect and retrieve from the database. However the App_Data folder is empty.
Here is are my connection strings:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-UsingEntityFramework-20161002112829.mdf;Initial Catalog=aspnet-UsingEntityFramework-20161002112829;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=tcp:xxxxxxxxxx.net;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxx;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Check your web.config and notice the connectionString and see the data source, maybe it is creating it under your SQL Server not inside the App_Data
The MDF File will be created when the database is created, and since this is a code first, the database will not be created unless you run the application and start connecting to the database, EF will create the database if it doesn't exist and will compare the schema to the schema in the Migrations folder and it will update the database if it is not up to date.
You can also open Nu Get Package Manager and run the command Update-Database to create and update the database.

host a database website with entity framework in the production server

I developed an asp.net website (using webforms) and for database connection I used Entity Framework. On my local computer everything is working fine. Now I try to host it I am having a problem. I have copied my files to the production server and attached my SQL Server database and set my connection string to:
<add name="ConnectionString"
connectionString="Data Source=SQL5003.Smarterasp.net;Initial Catalog=DB_9C4561_WFormBlog;User Id=DB_9C4561_WFormBlog_admin;Password=mydbpwd"
providerName="System.Data.EntityClient" />
but when I test my website am getting error:
Keyword not supported: 'data source'
When I removed "data source", it started complaining of "Initial catalog" keyword not supported.
Please help me out. You can refer me step by step tutorial or material that can put me through. Thanks in advance!
Try the below format, I have my database on smarterasp.net and it works well
<connectionStrings>
<clear />
<add name="ConnectionString" connectionString="Persist Security Info=False;database=DB_9C4561_WFormBlog;server=SQL5003.Smarterasp.net;user id=DB_9C4561_WFormBlog_admin;password=mydbpwd;Current Language=English;Connection Timeout=60;" />
</connectionStrings>

Categories