---
title: "How to get label text from table reference on database  based on TableName and FieldName"  
description: "How to get label text from table reference on database  based on TableName and FieldName"  
author: "ahmed abedelaziz"  
published: 2018-12-27  
updated: 2019-04-03  
canonical: https://www.mindstick.com/forum/34722/how-to-get-label-text-from-table-reference-on-database-based-on-tablename-and-fieldname  
category: "asp.net"  
tags: ["c#", "mvc5", "entity framework", "asp.net core"]  
reading_time: 3 minutes  

---

# How to get label text from table reference on database  based on TableName and FieldName

## SummaryProblem

=============

How to get label text from table reference on database based on TableName and FieldName dynamically from database and show on view createEmployee .

## Details Problem

Meaning i need to get label text dynamically from database not static from model

SO that Every Time i need to change text of label i will change it from database depend on [reference table](https://answers.mindstick.com/qa/114525/how-to-delete-rows-with-reference-table-data)

AND No need to change from code .

IF You give me function or any thing general because i have more models and view i need to make like that)

====Tools Used ====

Tools used [sql server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) 2012 and [visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2017 [asp.net core](https://www.mindstick.com/articles/12946/get-started-with-asp-dot-net-core-mvc-and-visual-studio) 2.1

===================

Database Have [two tables](https://www.mindstick.com/forum/159646/how-to-join-two-tables-in-oracle-to-get-single-line-results) Employee and Reference File(may be increase models and views so that if any thing general is prefer)

====Code==========

Query Get Data from reference Table

SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'

Models classes Include HRContext

public class ReferenceFile(have 3 key as composit keys(Code,TableName,FieldName))

{

public int Code { get; set; }

public string TableName { get; set; }

public string FieldName { get; set; }

public string EnglishtextforLabel{ get; set; }

}

public class Employee

{

public int EmployeeId { get; set; }

public string EmployeeName { get; set; }

public int EmployeeAge { get; set; }

}

public class HRContext : DbContext

{

public HRContext(DbContextOptions<HRContext> options)

: base(options)

{ }

public DbSet<Employee> [Employees](https://www.mindstick.com/articles/44463/business-to-business-vat-reclaiming-a-guide-for-your-employees) { get; set; }

public DbSet<ReferenceFile> ReferenceFiles { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)

{

base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Employee>()

.HasKey(t => new { t.EmployeeId });

modelBuilder.Entity<ReferenceFile>()

.HasKey(t => new { t.Code,t.TableName,t.FieldName });

}

}

Employee View Create(this static and i dont need . i need view labels get from reference table)

<div class="row">

<div class="col-md-4">

<form asp-action="Create">

<div asp-[validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework)-summary="ModelOnly" class="text-danger"></div>

<div class="form-group">

<label asp-for="EmployeeName" class="control-label"></label>

<input asp-for="EmployeeName" class="form-control" />

<span asp-validation-for="EmployeeName" class="text-danger"></span>

</div>

<div class="form-group">

<label asp-for="EmployeeAge" class="control-label"></label>

<input asp-for="EmployeeAge" class="form-control" />

<span asp-validation-for="EmployeeAge" class="text-danger"></span>

</div>

<div class="form-group">

<input type="submit" value="Create" class="btn btn-default" />

</div>

</form>

</div>

</div>

==============

Here i need to get label on view create from table reference not static field name

=======[Sample data](https://www.mindstick.com/forum/159310/write-a-node-js-script-to-seed-your-mongodb-database-with-sample-data)========

Sample data for ReferenceTable

Code TableName FieldName EnglishtextforLabel

1 Employee EmployeeId Code

2 Employee EmployeeName Name

3 Employee EmployeeAge Age

============Result I need==========

[As reference](https://answers.mindstick.com/qa/38867/the-word-hindu-as-reference-to-the-people-of-hind-india-was-first-used-byb-whom) table above sample labels on view create must be Give me the Result below :

Code

Name

Age

================

## Replies

### Reply by ahmed abedelaziz

can any one give me answer for question above if possible please


---

Original Source: https://www.mindstick.com/forum/34722/how-to-get-label-text-from-table-reference-on-database-based-on-tablename-and-fieldname

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
