I have got a assignment question from my college, there is a line as follows
This must be implemented using C# and utilize the Entity Framework classes.
this means Entity Objects or Entity Framework??
and can I implement Entity Framework as a C# desktop application
please help me to understand this. thank you
Yes you can use Entity framework for desktop application. Create one project as desktop application and add another as the business logic project, this should be one that uses entity framework objects to communicate with your database. Lastly, another project that will implement all your desired methods in relation to the entity framework project. This is the project that the windows application communicate with directly. Check out here for some tutorial
You can combine it as one project but I prefer separation of concern so you can compile the business logic as a dll. Entity framework is just one of the object relation mapping model and it can be used across various projects types. Others include NHibernate, LINQ to SQL etc
it is a library that can be used either on web or desktop .NET project: You can get it here
Related
I have a project for Entities and I am using ADO.NET code for normal CRUD operations on this entity. I would like to map my entity name to table names, Could you please provide me a way to do it. With .Net Standard I could use System.Data.Linq.Mapping. But my project is in .Net Core 2.2 and I cannot add these as a reference, tried changing target framework, but my other projects are not compatible. Kindly advise me how do I do it.
I can see a couple of options.
1) Create a Mapper class that accepts T1 & T2.. And do the mapping manually for each property.
2) Use a library such as Automapper that does all this for you automatically (https://github.com/AutoMapper/AutoMapper)
I had a conceptual question about EF.
I am pretty new to the idea of an ORM in general, so I wanted to get some clarification on somethings:
I have an existing database, and I want to convert the data I am pulling from that data into objects that my application can interact with as objects, rather than just data.
An ORM will accomplish that, correct?
In EF can I create methods specific to my objects? For instance, can I make it so my application can call something like employee.ViewDetails() Where employee is an object?
If so, is there a simple tutorial you could recommend?
Is EF portable between applications? Meaning, is it easy to build an EF structure and then port it to multiple applications?
I can just do that by referencing it from different solutions, no?
Thanks for all the help
Before Answering your Question let me give you short brief about Entity Framework
Using the Entity Framework to write data-oriented applications provides the following benefits:
Reduced development time: the framework provides the core data access capabilities so developers can concentrate on application logic.
Developers can work in terms of a more application-centric object model, including types with inheritance, complex members, and relationships. In .NET Framework 4, the Entity Framework also supports Persistence Ignorance through Plain Old CLR Objects (POCO) entities.
Applications are freed from hard-coded dependencies on a particular data engine or storage schema by supporting a conceptual model that is independent of the physical/storage model.
Mappings between the object model and the storage-specific schema can change without changing the application code.
Language-Integrated Query support (called LINQ to Entities) provides IntelliSense and compile-time syntax validation for writing queries against a conceptual model.
Going Back to your first Question
Yes
Entity framework is useful in three scenarios.
1- First, if you already have existing database or you want to design your database ahead of other parts of the application. (Which is your current case)
2- Second, you want to focus on your domain classes and then create the database from your domain classes.
3- Third, you want to design your database schema on the visual designer and then create the database and classes.
2) in EF can I create methods specific to my objects? For instance, can I make it so my application can call something like employee.ViewDetails() where an employee is an object? If so, is there a simple tutorial you could recommend?
Yes Sure Take a look on this:
- https://msdn.microsoft.com/en-us/library/dd456847.aspx
- http://www.asp.net/mvc/overview/older-versions-1/models-data/creating-model-classes-with-the-entity-framework-cs
3) Is EF portable between applications? Meaning, is it easy to build an EF structure and then port it to multiple applications? I can just do that by referencing it from different solutions?
you might need to Implementing the Repository Patterns
Have a look at this Amazing tutorial
http://blog.gauffin.org/2013/01/repository-pattern-done-right/
http://rycole.com/2014/01/25/entity-framework-repository-pattern.html
Hope this helps!
Wish you the best :)
Blubberbo,
There are various ways to work with EF, they are Code First, Model First and Database first.
More information can be found in the below SO post.
Code-first vs Model/Database-first
1) You can use LINQ to SQL or LINQ Objects in context with an ORM like EF to interact with Objects.
2) If you would like methods specific to specific types, then you might want to take a look at writing extension methods for specific types.
More information here
https://msdn.microsoft.com/en-us/library/bb311042.aspx
3) To make it portable, you might want to build abstractions around it, like for example you might want to write repository classes to separate the DB layer that uses EF and the layer that calls it(a.k.a the repository layer).
More info can be found here
http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
Hope that helps,
Praveen Raju
You might have encountered this type of question before but in my case, it's a bit different scenario and I cannot find a feasible answer. (It might exist already, however I was not able to find one).
I'm working on a business application which has the entire functionality split into multiple class libraries. I'm using Entity Framework and I'm not sure which is the right place to include it? In my case, I've these libraries:
Project.Library.Core
Project.Library.Models (Contains the entity data model and entities).
Project.Library.Auth (Contains authentication related and user management classes).
and similar classes who frequently use the entities and the db context.
In order to make this work, I've to install Entity Framework in every library separately. Eventually they will be included in a number of ASP.NET MVC Web Applications. I'd have installed Entity Framework directly into the web apps but this application will have mobile apps in the future along with a possible windows store app. In that case, I can simply set up a ASP.NET Web API and use the existing class libraries to generate the required data. This is the only factor holding me back from incorporating Entity Framework directly into the web apps.
So what's your opinion on this? Include Entity Framework in every library separately (required to function properly) or simply include in the web app and later follow the same approach for the Web API?
Thank you.
You only need to "install" EntityFramework into one place: Project.Library.Models. Assuming standard code-first objects as your DTOs, you won't need a direct reference anywhere else as long as you wrap the context object with a Data Access Layer.
Adding a reference to that assembly will cause the requisite DLLs to be included with your apps, web sites, etc. Note that if you are using EntityFramework.SqlServer, the transient dependency won't be detected by Visual Studio so you need to do something like:
class Include
{
private Include() { }
private SqlProviderServices IncludeSql;
}
Somewhere in the models project so that DLL is copied over also.
Hi I'm new to Entity Framework so excuse me if this question seem simple, but I have tried to find an example or question where this is described.
I have built a webApi interface with classes in what I call an eventmodell. The Interface and model is working well to receive stuff. But now I would like to build the CRUD functions to the database with Entity Framework.
I have added an empty code first model, but then I don't now how to generate csdl, msl and ssl files needed to create the database.
I have added Empty EF designer model but have found no way of adding an existing class to the designer.
I have installed EF Power Tools but that didn't help.
You seem to have a misunderstanding on how Code First works as compared to Database First.
There is no designer needed in a Code First approach. You add classes to your model, setup a DbContext and use Migrations to setup, and then at later stages, alter the database structure.
Checkout this tutorial: Getting Started with Entity Framework 6 Code First using MVC 5
Many tutorials on Entity framework are related to web-based application. But is Entity only for the web?
Can the regular windows based client application, or any other application built using c#.net for that matter, use Entity as an abstraction for DB connectivity?
Entity Framework is a very sophisticated ORM (Object Relational Mapper) which allows complex mappings between Database tables and .NET Framework classes. It is not bound to any specific project type, or even any specific .NET language. You can use Entity Framework with C#, F#, VB.NET, and even Python, if your library is built correctly.