I work with .net4. I've created an ADO.NET Entity Framework data model and add new entity with scolre property.
I've created a Database1.mdf with a data set.
Now I click on Generate database from model -->
select `Database1ConnectionString` -->
create `Model1.edmx.sql`
Now when I click on Execute sql -->
servername=`username\SQLEXPRESS` -->
Click on connect
I get an error:
Database 'Database1' does not exist. Make sure that the name is
entered correctly.
Why?
Select a corresponding template in the model properties window. Then right-click on the diagram and run the Create Database from Model wizard by choosing Generate Database from Model from the popup menu.
Note:
The default schema name for Microsoft SQL Server database is dbo. Don't forget to change it to the necessary one before the code generation.
Here is a DDL script generated for the current model.
As a result of these steps you will obtain a valid database-specific DDL script. You can run this script against your database to create a valid database schema.
Related
Right click on the EF Model Designer surface and choose Update Model from Database.
In the dialog box that pops up, you should be able to browse the database, and select objects to add. But in this case, nothing can be selected:
Removing the Connection String from the App.Config and allowing the Designer to re-add it did not resolve the issue.
The credentials used in the Connection String when copied and pasted in SSMS.
The database can be browsed from the VS Server Explorer window.
Creating a new blank EF project and repeating from there works fine.
What could be causing this?
One of 2 problems exist, the Model already has the Tables/SP/View you are looking for or the Login does not have the Authority the access those Tables/SP/View.
One of the factor unable to select any checkbox in Update Wizard is you don't have any updates in your database, therefore entity framework doesn't allow you to select.
If your scenario is not the factor above, you may try the method I listed below:
I had this issue too and I noticed that I didn't grant the db_owner under Database role membership for my database (eg 22Aug_M) in Microsoft SQL Server Management Studio.
After I checked it and it works as normal.
Im trying to use Entity Framework on my .NET 4.0 Web Site. I already have installed Entity Framework 6.1 and i "Add New" ADO.NET Entity Data Model to my site using a valid connection string , and I select my table. I know this is a valid table with several columns and rows of data. After the creation is finished I am left with only a .cs file with no properties and a new connection string added to the web.config, but there is no .edmx file created. I know the SQL user in the Con String has read/write permissions and this is a valid table. Any clue as to what i may be doing wrong?
Have you tried to change the values of this new connection string with your values?
Take a look of this link and retry..
https://msdn.microsoft.com/en-us/data/jj206878.aspx
PS: I think that you should have created a "Project" and not a "new WebSite" using:
"Folder>New>Project> ASP Web App" in VS
Doing this you have all ready to go (references, EF etc..) then you could even start from a empty virgin model, or EF designer from database where you could easly manage or create entities, relations etc.
I am new and beginner in light-Switch,
I am doing light-Switch with MVC.
Let me explain my scenario:
First I have created one light switch application. In this app having one project is called [ProjectName].Server
Then I've Connect my SQL database in Light-Switch application. And try CRUD operation via Light-Switch screen and its working fine.
In This server project I've create MVC structure like controller, model and views. using Click Here
Then I've create simple Index view in Home controller and its open successfully.(via open browser from desktop client)
Now i want to get light-Switch table data(records) in my controller via entity Framework or light-Switch data context. suggest me easiest way..
I don't know how to get data in controller using light-switch data context. so I've try with entity framework using DbContext and DbSet.
But i got error:
One or more validation errors were detected during model generation:
LightSwitchApplication.Data.[EntityName]: EntityType '[EntityName]' has no key defined. Define the key for this EntityType.
[EntityName]: EntityType: EntitySet '[EntityName]' is based on type '[EntityName]' that has no keys defined.
I've also got some solution for light-switch data context here Click Here
I've try to implement but not getting ApplicationData and CreateContext See Attached.
Your answer will appreciable
Thanks,
Jatin
See my article: An HTML MVC LightSwitch Security Administration (http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/3281/An-HTML-MVC-LightSwitch-Security-Administration.aspx) for an example.
Basically you need to have these includes:
using Microsoft.LightSwitch.Server;
using Microsoft.LightSwitch;
using LightSwitchApplication.Models;
I am porting my SQL Server database to Azure SQL. The database has been replicated correctly and is now accessible from my existing web application.
However, the first time it was executed with the Azure SQL connection string, it showed "Invalid Object" for a table name used on the log in page.
I was able to correct it by adding the schema name [dbusername].[tablename] in place of [tablename] in the code.
Now since it is an extensive application, with over 300 ASPX pages and 30 tables, I'm wondering do I have to use the Find-Replace tool in Visual Studio or am I missing a setting that can help me to assign the default schema name while executing all queries ?
Set the default schema for your user.
USE MyDataBase;
GO
ALTER USER MyUser WITH DEFAULT_SCHEMA=MySchema;
GO
I believe this article will help you.
http://blog.sqlauthority.com/2008/12/26/sql-server-fix-error-msg-15151-level-16-state-1-line-2-cannot-alter-the-login-sa-because-it-does-not-exist-or-you-do-not-have-permission/
I'm not even quite sure how to properly word this, but here goes.
I have two .net web applications. One provides a WCF data service ("DEPT_DataService") which provides access to a number of entity sets ("DEPT_Entities"). The other is an MVC2 application which provides a web interface, and also has its own ADO.net entities which are backed by a local MSSQL database.
Using an overly-basic structure to illustrate:
Let's say the WCF data service application includes a single entity set, "Departments", backed by a "Departments" table in its local SQL database. This contains a list of all the departments in the company, along with the employee ID of the primary contact for that department.
Let's also say that the MVC2 application includes a single entity set, "Employees", which contains a list of a bunch of people, including their name and their employee ID.
I've got DEPT_Entities added to the MVC2 application as a Service Reference, "DEPT". When I look at that service reference in the Object Browser, I see "DEPT_Entities" and "Departments".
What I want to do is define a relationship that allows me, via Linq, to refer to something like this:
Employee firstEmployee = db.Employees.First();
Department[] firstEmployeesDepts = firstEmployee.Departments.toList();
...in other words, I essentially want a navigation property that provides a one-to-many relationship between the Employee entities found in the local database and the Department entities found in the remote data service.
Is this doable? How?
Thanks!
If you want to access the databases directly without a webservice:
You can use SQL Server tricks (Remote Query inside of a View to a Linked Server) to make Linq2SQL be able to query the remote table. Essentially, you simulate that the remote table is just an ordinary local table (a view, but L2S does not care).
This will work but it will not be pretty.
If you want to have a webservice in front of one of the tables: This will not work because L2S does not understand webservices.
In fact, I would architecturally advise against hinding the fact that you are calling a webservice.