Nargzul
asked on
How to use Linq to entities
Hi!
I'm trying to use an LINQ to entities connection to connect my ASP application to the database(MS SQL), but, after many research, I don't find how to create model from the database, how to make it, Is there a new element to create in visual studio?
I'm trying to use an LINQ to entities connection to connect my ASP application to the database(MS SQL), but, after many research, I don't find how to create model from the database, how to make it, Is there a new element to create in visual studio?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
by the way, I would recommend doing your research before commiting to L2E - IMO it is still immature compared to other ORMs such as Linq-to-SQL, NHibernate, etc.
Hi Nargzul;
To create the model for the Linq to Entity in your project do the following:
1. Go to the Solution Explorer and right click on project name and select Add -> New Item
2. In the Add New Item window select ADO.Net Entity Data Model and click Add button.
3. When the Entity Data Model Wizard window opens select the Generate from Database option
4. Click on the Next button.
5. In the Choose Your Data Connection Select the connection to the Database or create a new one.
6. Click on the Next button.
7. In the Choose Your Database Objects select the Tables, Views and Stored Procedures to be in the model.
8. Click on Finish.
9. The Data Model will then be created and the design surface will be displayed.
Fernando
To create the model for the Linq to Entity in your project do the following:
1. Go to the Solution Explorer and right click on project name and select Add -> New Item
2. In the Add New Item window select ADO.Net Entity Data Model and click Add button.
3. When the Entity Data Model Wizard window opens select the Generate from Database option
4. Click on the Next button.
5. In the Choose Your Data Connection Select the connection to the Database or create a new one.
6. Click on the Next button.
7. In the Choose Your Database Objects select the Tables, Views and Stored Procedures to be in the model.
8. Click on Finish.
9. The Data Model will then be created and the design surface will be displayed.
Fernando
ASKER
I've saw many times in many tutorial this "Ado.Net ENtitiy data model", but when I go on the new item, I don't find anthing containing "ADO".
Must we install anything?
I've visual studio 2008.
Must we install anything?
I've visual studio 2008.
Yes, Linq to Entity was added to VS 2008 with VS 2008 SP1. You will need to go to the Microsoft update site and update VS 2008 and .Net Framework 3.5 with SP1, Service Pack 1.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help. I've now a model. in your link, I don't see how to get object from database.
Creating is not problem, but how do we get an information?
Creating is not problem, but how do we get an information?
a quick example is shown with a gridview:
Display your data
Now that we have put a few objects in to the database, we can go and check it out. Later we will dig in with code, but first we will use a LinqDatasource/GridView:
Drag a LinqDataSource (LDS) on to the page and click Configure Data Source from the little square on the upper right of the LDS
Choose your Object Model and click Next
Choose your table and click Finished
Drag a GridView (GV) on to your page
In the GV option box, choose your datasource from the dropdown
now just view your page:
Is that what you were looking for?
Display your data
Now that we have put a few objects in to the database, we can go and check it out. Later we will dig in with code, but first we will use a LinqDatasource/GridView:
Drag a LinqDataSource (LDS) on to the page and click Configure Data Source from the little square on the upper right of the LDS
Choose your Object Model and click Next
Choose your table and click Finished
Drag a GridView (GV) on to your page
In the GV option box, choose your datasource from the dropdown
now just view your page:
Is that what you were looking for?
ASKER
But by exemple, to check that a user is valid, something like the equivalent of:
select * from users where username="Bryan" AND password="lkajdlskjadskfja ldsjf" And isActive="true"
geststockEntities gse = new geststockEntities();
User usr = gse.User.First(u=>u.Userna me==this.u sername.Te xt);
But how can I have many condition in the "where clause"?
select * from users where username="Bryan" AND password="lkajdlskjadskfja
geststockEntities gse = new geststockEntities();
User usr = gse.User.First(u=>u.Userna
But how can I have many condition in the "where clause"?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
And, how can we know if the object loaded is correct? The var is null?
if the var is null, there is nothing in your db that matches that criteria exactly - could be case, spelling or anything like that.
ASKER
I've an exception when there is no corresponding tupple, is it right?
tupple?