I know Linq to SQL work such as setting META attributes around your model. What i am looking to do is building my model then setting this model to work with EF 4.
Are the same approach working with EF 4 ?
Is this called the Code-First approach or its totally something else ?
Ive done some research but i can't seem to figure out how exactly to map a domain to work with EF 4. This include keys/relations integrity.
I would love to see a simple code example with some explanations.
Thanks.
Model-first development allows you to build the model in the designer, then generate the database based on that model. Code-first allows you to generate the database based on your code, or use the code to work with an existing database too.
Both those options are viable; for code-first, V5 has a lot of improvements you will want to look out for.
HTH.
Related
I have ben following through a tutorial that shows how to get started creating a Web Forms Application in ASP.NET...and have got to the part where you create Data Classes. These assume you are starting from scratch and generating the database from code - however - I already have a database created and populated from elsewhere.
Entering line by line to create the Class for each table seems very laborious. (I'm using VB.Net and VS 2013 by the way)
Q1. Can anyone help by suggesting a more automated way of doing this? Surely there is a tool to grab the schema?
Q2. Although the tutorial mentions Entity Framework and Code Behind briefly - having done some reading and research - I am very confused by all of the different terms for data access. Am I using ADO.NET ?? Is the methodology called Code Behind as opposed to something else? Are there better ways to connect to a database and Read/Update/Delete records.
Q3. If I want to use a Data Grid to show the data do I use the generated classes to do this - or just 'bind' the grid directly to the database?
I have been a developer for 40 years but the newer .Net models are causing me some confusion so any advice gratefully received. (and any simple books or tutorials that can be suggested would be helpful).
Thanks
Q1: What you want is to generate "EF Designer from database" by using a Entity Data Model.
In your project add a new item and look under "Data".
What this technique does is auto generating entity classes from your predefined database.
Q2: I suggest you read Getting started with Entity Framework. "Database First" is just a description of how you want to use the Entity framework - by saying you already have a database structure.
Q3: In this case if you use Entity Framework and the "database first" mechanism to generate entities you can databind the gridview from the result of a entity LINQ query, please see this example: Tutorial: Databinding
I'm using Entity Framework 5 with large database with 600+ tables (haven't counted stored procedure and views yet). After few start and running using Visual Studio 2012 I get Out of Memory error when trying to Update my Model.EDMX file (using right click Update from Database) or simply while trying to compile.
Quick google search says many people faced similar problem and someone in one forum suggested to use multiple EDMX files to avoid this.
(link http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/b4ce1494-a0b4-42c6-af56-4ecbfeb83e29)
My question is
1) Is there any way I can avoid this error and use large number of tables without trouble with EF?
2) Is Entity Framework model is right ORM for me for large enterprise database? If not, can someone suggest me good one?
Thanks in advance
To answer your first question.
I have found that updating the Entity Framework does not seem to work reliably in all cases.
Have you tried deleting all the objects in the model and inserting them again? It may be an acceptable workaround.
I'd recommend spending some time looking into nHibernate. It's not as user friendly in terms as UI than Entity Framework but that should be an advantage for you if you are dealing with a large number of tables.
http://nhforge.org/Default.aspx
Also, you're aware that you don't have to map all of the tables in your Entity model? You can just bring in the ones you need. I'm assuming that you don't need all 600 tables for what you're doing.
I'm attempting to setup Entity Framework using Code First on an existing database. The database isnt in great shape (poor naming convention and some constraints are needed). The application I'm building is an MVC app. I have a "Model", "Repository", and "Web" (mvc) tiers.
To setup EF and map my model objects (POCO objects), is it required that I match my objects to database tables? Can I, instead, use my own stored procedures for CRUD operations? Would it help if I use WCF data services?
I'm planning on using fluent configurations to map my objects, but having some issues due to the database schema. I'm know considering redesigning the database just to get EF to map correctly. Any suggestions would be greatly appreciated!!
Looks awfully similar to this question:
Does Entity Framework Code First support stored procedures?
The answers there may be helpful to you, as well as the discussion surrounding how Code First and Stored Procedures don't make a whole lot of sense.
Wow, Julie Lerman answered!
Yes, it's possible, but not particularly easy. In particular, you must call context.Database.SqlQuery<T>() where T is the entity type you want to return, and your SQL must match up to that entity type. Otherwise, you will have to massage a result set into a type.
In general, you will have to do most of this manually, although you could probably figure out a T4 template to generate it for you, or maybe use some other tool like CodeSmith.
I'm Looking for some samples (will be better if they are open source) that enabling Programmer to Generate UI from Database.
I want to review them for the framework that i want to develop for myself.
Already i reviewed ASP.NET Dynamic Data and Nettiers.
Also i welcome your suggestions , tips , comments.
Have a look at a project I'm about to release, CodeGenerator. There is a sample project which illustrates how you can use CodeGenerator to quickly generate an entire administrative site. Have a look and let me know your thoughts.
BTW, this is just a small example of what CodeGenerator can do.
While perhaps not directly what you may want, have a look at Entity Framework Code First to let the code drive the DB model and it works well with existing databases.
Then with MVC you could use MVCScaffolding to generate your views but in this case it uses the Models not the DB directly.
It's a slightly different way than you might be looking for but it is still worth a look to help you as you look at this.
I am new to the code generation tools and I would like to know how does a tool like LLBGen Pro compares with the Entity Framework?
On top of that my boos is really looking into a tool called CodeOnTime http://codeontime.com/default.aspx because he likes their good UI support.
I am asking here because I really want an unbiased opinion.
I am not sure if LLBGen can also generate the UI. So far all the development in the house we do it the classic way coding each layer manually. However we are in need of a fast prototyping tool.
Any advice to help me choose wisely will be much appreciated
thanks in advance.
Have you taken a look at CodeSmith Generator? It's a template based generation tool with Visual Studio integration, so by definition all templates are open source, and it has advanced features such as generate on build that keep your project up to date with your data source at all times.
Also, the CodeSmith team is about to start working on an official set of EF templates, but for now they offer several different ORM options including LINQ to SQL, NHibernate, .netTiers, CLSA, etc.
The thing is that there are code generators and object relational mappers (ORM) and code generators that do object relational mapping.
Something like NHibernate is a pure (ORM) and doesn't generate any code, it just provides you with an object persistence layer.
Llblgen is a code generator that generates code that performs the functions of an ORM but you can actually see the code and can override it with custom behaviour. Llblgen won't generate your UI for you and it isn't designed to. It's heavily focused around data access.
Then you have tools like CodeSmith or the built in T4 generator that comes with visual studio which you can use to create templates and then they will generate anything you want, provided you write your own templates. I've worked for companies that have invested thousands into writing their own templates.
Finally there are complete tools like CodeOnTime or IronSpeed which generate entire applications for you. This sounds good in theory, and is great for small CRUD type applications, but you lose a lot of flexibility with tools like these as they often have conventions which you are required to work around and once you start getting into heavy customization, tend to get in your way.
You should ask yourself:
Do I just need something for accessing my data? if so, you could use an ORM
Do I need to generate a highly customized UI? if so, you'd probably be best avoiding the tool like CodeOnTime and IronSpeed
I've used both LLBLGen and Entity Framework. In my experience, they are roughly equal in capability, especially now that Entity Framework 4 has been released. NHibernate is also in this realm and should be considered if you're looking to compare the top ORM tools for .NET.
I would recommend downloading the LLBLGenPro demo to evaluate it. According to Frans Bouma's blog, LLBLGenPro offers enhanced features not present in the out-of-the-box Entity Framework tooling built into VS.NET 2010.
ORM tools like EF and LLBLGen do not generate UI. For that you will need something like IronSpeed (not recommended, I don't like the code generated) or the IdeaBlade DevForce products, which I have not used.