I have a project about survey application on web. I have to use MVC 4 Code First and I have to use abstract class to derive other classes. I just need a logic of this structure and coding. I've shared my database schema with you below which is built on MySQL Workbench. I want to use Code First to make this schema possible for my Model Classes. I need to finish this project until Monday.
Schema :
http://imageshack.com/a/img547/4278/q2or.png
Related
I have a database for which I want to generate the repository and entity/model classes with all CRUD operations.
To achieve this I found a tool, named Entity Developer
(https://www.devart.com/entitydeveloper/download.html), which is generating all the stuff, but without CRUD operation for each entity as tools is generating just an empty class named ABCRepository, so again I have to write the code for each repository class. Though same task can be achieved from Entity framework, except than the repository classes( which does not contain any CRUD operations).
Can any one help me to get the solution?
Update: I have followed this tutorial (https://dzone.com/articles/implementing-the-repository-pattern-using-c-and-en), according to this, Entity Developer should generate the "Repository per entity type" with operations, but while following and creating the Data Model, I get only empty ABCRespository and IABCRepository classes. I tried multiple ways to create the Data Model, yet not successful.
To achieve this I found a tool, named Entity Developer (https://www.devart.com/entitydeveloper/download.html), which is generating all the stuff, but without CRUD operation for each entity as tools is generating just an empty class named ABCRepository
Please check the Generate Partial property of your Repository And Unit of Work template. If it is set to True (by default), the code is generated in ABCRepository.Generated.cs. The code file ABCRepository.cs is created for user code that will not be overwritten by the designer.
I created a C# data layer using Entity Framework 6 via the Code First From Database wizard which defined all of the C# classes which represent their respective tables.
There was a table that I missed and I'm looking for a way to generate another class to represent the table.
Is there a way to have this class created after the initial wizard has already been run?
The reverse engineer tool is meant to be used once in code first. Once it has been used you would just add the class that represents the table along with the other entities. If you are adding tables in the database after you have used the wizzard then you are not truely using code first. Just add a POCO class to the entities folder the tool generated and model it after the others. Once you have done that you use the package manager console to add-migration which aligns it back with your schema, next you use update-database to push the changes back to SQL Server.
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
I have a Solution with one project is Entity Framework and have my ASP MVC project, I looking for some advice or opinion about the idea of create in top of my POCO objects and the DBContext, a Business Logic Layer with static classes that have the all the methods (example a ContactBLL class with GetContactByID, GetAllContacts, GetContactsByType) to allow the access to the model data and that can be accessed in the Controllers Actions. In that way I don't have to put the implementation code of this methods in Controller Actions methods, and it can be reusable invoking this methods in other Action Controllers. I will appreciate your opinion because it could guide me to respond a question I've asking to myself around a week based in the answer to this one (about where to define the DBContext and how use it).
You can create different projects according to core functionality.
Data Access Layer(DB context and repository etc.) you can make Project.DataAccess, it will have only db context class and repository.
Business Logic Layer(Project.Business) it will have business logic and make call to data access layer.
UI Layer(Project.WebUi) it is mvc project.
and so on.
for detail info you can see this http://prodinner.codeplex.com/ code
Create separate class library for your POCO,
then create another class library for your repository, this should
include only the interfaces needed for your repository
and the implementation will be on another class lib like Project.EF,
Project.NH which will include Entity Mapping, Migration, Repository
implementations. but in reality, chances are you wont be changing
your ORM lib once it was implemented because it will just cause you
a lot of headache(just my 2cents).
you'll create your business layer(class lib) and
web project as separate lib. Models folder of your MVC project will contain your ViewModels.
this is what Im using right now and of course not the best structure, it just something that Im happy with :). hope it helps.
In general, there are four standard projects in a ASP.NET MVC - Entity Framework solution. They are 1) MVC, 2) Core/Business Logic Layer(BLL), 3) Data Access Layer/DBContext (DAL) and 4) Common/Utility.
Standard MVC project consists three main elements which are Model, View and Controller. However, middle to complex solution usually cuts off the Model element from MVC project and moves it back to BLL, we call it as ViewModel(POCO). Following this structure, MVC project is now responsible for employ/use the services from BLL and control the UI through controller.
Business Logic Layer (BLL) is the core of implementing business logic. It is responsible for serving request from the MVC project and work with DAL to persist data. As said above, BLL is the place to define ViewModel, its relations as well interface/ abstract class to support implementing design pattern. Viewmodel(POCO) is likely mapping one-one to data entity at DAL but we do not use the data entity directly on View. Following this structure will help to increase the customization on ViewModel like adding constrains
DAL is the place for DBContext and its data entities.
Common project consist of shared functions like Logging which is used in 1) 2) and 3)
Please read more at
https://www.codeproject.com/Articles/70061/Architecture-Guide-ASP-NET-MVC-Framework-N-tier-En
https://chsakell.com/2015/02/15/asp-net-mvc-solution-architecture-best-practices/
I have an existing database that I want to generate its POCOs but I want to end up with model classes outside .tt file, without giving partial definition and "auto generated" comment header for each class I want to have a result like I started building POCOs from scratch. Is there a process to get this result ? Regards
I want to regenerate my database and start updating model from POCOs using migrations
Update : After editing Template File (.tt) I could remove the header comment and partial definition. I think I could get my work done manually. Now, I just need to Exclude .tt file and its sub classes from project and then add only my business classes to the project again.
You can use Entity Framework Power Tools Beta 3 extension to generate your pocos. It has an option to reverse Engineer Code First which Generates POCO classes, derived DbContext and Code First mapping for an existing database.