<div class="gmail_quote">Hi all,</div> <div class="gmail_quote"></div> <div class="gmail_quote">1. Which is the best model of EF(Entity Framwork) = code first, database first etc with asp.net mvc3</div> <div class="gmail_quote">2.
And should i use backend (sql server) as i do with ado.net i mean creating function, sps etc or i should go with the linq without sp and functions. linq generated sql ( i think it must be slow becoz of mapping
and simple sql genration)</div> <div class="gmail_quote"></div> <div class="gmail_quote">Thanks A lot</div>
The best EF development approach (Code First, Model First, or Database First) depends on your scenario. If you already have a database and/or a DBA maintains your database, Database First is probably best, but you can still use the Code First API. If you
want to just write Code and have the database created for you, Code First is best. See this tutorial for a description of the different approaches:
After the discussion of options, the remainder of the tutorial series uses Code First.
Code First does not support automatic use of Stored Procedures, but Database First does, so the answer to #2 will depend in part on what you decide about #1.
thanks but if i use database first thn Ef will create class for all the tables. than what about the view model for MVC ?
and i m still confused about it what is the best approch(performance) and weather i should go with stored proc or linq generated sql
as well as the frist code approch create a database every time if model changes it mean there si some thing which checks all the tables in the database which compaire the tables with models
you have to create your controllers and models. You can use code generator to create DbContext classes for each of your table. If you change the database, it will automally generate those classes again. You will lose all the customized code in those classes.
Your can turn it off for mannully update those classes, so it won't be a problem. or create poco classes yourself.
It depends on your application. Overall, i I like Database First better if your application/database is big. If you change column name, you can lose data in the code first approch, too. For small websites you can go with code first, then switch to Database First
later. I would never do Code first approch for big application.
It depends on your application. Overall, i I like Database First better if your application/database is big. If you change column name, you can lose data in the code first approch, too. For small websites you can go with code first, then switch to Database First
later. I would never do Code first approch for big application.
Thanks Eileithyia,
but if i go with Database first because my appilcation database is would be big. than all the classes will be genrated by Ef in .Edmx after that if i create my models thn how can i mapp my class with the .edmx files or is there any way to do that. and last
question is i should go with linq generated sql for insert update delete or i should use stored proc for every DML operation as we do with Ado.net
but if i go with Database first because my appilcation database is would be big. than all the classes will be genrated by Ef in .Edmx after that if i create my models thn how can i mapp my class with the .edmx files or is there any way to do that.
You can just import several model entities that you want to use,there's no need for you to import them together into the edmx file。
himanshuKaushik
last question is i should go with linq generated sql for insert update delete or i should use stored proc for every DML operation as we do with Ado.net
Just depends on your need:
1)If your task is very easy (to a single table's dealling with that……):Just use CRUD generated by EF。
no views models are which will work on the view pages .cshtml. because EF makes a single file for all the mapped classes from the sql server tables and dbcontext.
himanshuKaus...
Member
16 Points
11 Posts
MVC and Entity framework
Mar 02, 2012 04:13 AM|LINK
tdykstra
Contributor
4463 Points
624 Posts
Microsoft
Moderator
Re: MVC and Entity framework
Mar 02, 2012 04:21 AM|LINK
The best EF development approach (Code First, Model First, or Database First) depends on your scenario. If you already have a database and/or a DBA maintains your database, Database First is probably best, but you can still use the Code First API. If you want to just write Code and have the database created for you, Code First is best. See this tutorial for a description of the different approaches:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
After the discussion of options, the remainder of the tutorial series uses Code First.
Code First does not support automatic use of Stored Procedures, but Database First does, so the answer to #2 will depend in part on what you decide about #1.
daisydain
Member
222 Points
51 Posts
Re: MVC and Entity framework
Mar 02, 2012 04:25 AM|LINK
Hello,
Check out the links below. It will help you
http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
http://msdn.microsoft.com/en-us/data/gg685467
http://davidhayden.com/blog/dave/archive/2011/04/13/AspNetMvc3SampleApplicationMusicStore.aspx
himanshuKaus...
Member
16 Points
11 Posts
Re: MVC and Entity framework
Mar 02, 2012 05:34 AM|LINK
thanks but if i use database first thn Ef will create class for all the tables. than what about the view model for MVC ?
and i m still confused about it what is the best approch(performance) and weather i should go with stored proc or linq generated sql
as well as the frist code approch create a database every time if model changes it mean there si some thing which checks all the tables in the database which compaire the tables with models
Eileithyia
Member
141 Points
102 Posts
Re: MVC and Entity framework
Mar 02, 2012 07:16 PM|LINK
you have to create your controllers and models. You can use code generator to create DbContext classes for each of your table. If you change the database, it will automally generate those classes again. You will lose all the customized code in those classes. Your can turn it off for mannully update those classes, so it won't be a problem. or create poco classes yourself.
It depends on your application. Overall, i I like Database First better if your application/database is big. If you change column name, you can lose data in the code first approch, too. For small websites you can go with code first, then switch to Database First later. I would never do Code first approch for big application.
himanshuKaus...
Member
16 Points
11 Posts
Re: MVC and Entity framework
Mar 03, 2012 02:55 AM|LINK
Thanks Eileithyia,
but if i go with Database first because my appilcation database is would be big. than all the classes will be genrated by Ef in .Edmx after that if i create my models thn how can i mapp my class with the .edmx files or is there any way to do that. and last question is i should go with linq generated sql for insert update delete or i should use stored proc for every DML operation as we do with Ado.net
thanks again
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: MVC and Entity framework
Mar 04, 2012 12:30 AM|LINK
You can just import several model entities that you want to use,there's no need for you to import them together into the edmx file。
Just depends on your need:
1)If your task is very easy (to a single table's dealling with that……):Just use CRUD generated by EF。
2)If it's a little complicated,Use SP instead。
himanshuKaus...
Member
16 Points
11 Posts
Re: MVC and Entity framework
Mar 04, 2012 02:08 AM|LINK
Hello decker and thanks
now i go that where sps shud be used.
but
my question was how will i mapp my view models classes with the Ef generated class.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: MVC and Entity framework
Mar 04, 2012 03:16 AM|LINK
What's that?Is that a View in SQL database?
himanshuKaus...
Member
16 Points
11 Posts
Re: MVC and Entity framework
Mar 04, 2012 03:20 AM|LINK
no views models are which will work on the view pages .cshtml. because EF makes a single file for all the mapped classes from the sql server tables and dbcontext.