8

I am using Entity framework v 6.1.1 in my application.

My database has 2 tables User, Location.

User table
-----------
UserID
HomeCityId(FK -> LocationId)
CurrentCityId(FK -> LocationId)
Location table 
LocationId
LocationName

Using DB First approach, I created a Entity data model for these two tables.

The generated entity class of User table

public int UserId;
public int HomeCityId;
public int CurrentCityId;
public virtual Location Location { get; set; } 
public virtual Location Location1 { get; set; }

Is there a way to name these virtual properties as HomeCity and CurrentCity instead of Location and Location1?

Santosh Panda
  • 7,235
  • 8
  • 43
  • 56

1 Answers1

0

In case of Entity Framework Database First Approach, using MVC, Entity Framework, and ASP.NET Scaffolding, you can create a web application that provides an interface to an existing database. The automatically generate code enables users to display, edit, create, and delete data that resides in a database table. The generated code corresponds to the columns in the database table.

To add Data Annotations to the data model to specify validation requirements and display formatting- changes to the auto generated class by Entity Framework is not recommended, as it is sure to get overridden whenever you update your EDMX data model, so metadata & partial class.cs files are created.

Also, note that all the files- EDMX , PartialClasses.cs and Metadata.cs should reside at same location in your application directory.

Please refer this tutorial: Enhance data validation and display formatting for EF Database First with ASP.NET MVC app

Xplorer
  • 49
  • 7