问题
如何从数据库中基于TableName和FieldName的数据库表引用中动态获取标签文本,并在视图createEmployee上显示。
详细信息
意思是我需要从数据库动态获取标签文本,而不是从模型静态获取
因此,每次我需要更改标签文本时,我都会根据参考表从数据库进行更改
并且无需更改代码。
如果您给我功能或任何常规的功能,因为我有更多的模型和视图,我需要像这样
工具使用了sql server 2012和visual studio 2017 asp.net core 2.1
数据库有两个表Employee和Reference
引用表(具有3个键作为组合键(Code,TableName,FieldName))
模型类包括HRContext
public class ReferenceFile
{
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 { 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 });
}
}
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-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>
查询从参考表获取数据
SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'
在这里,我需要在从表引用而非静态字段名称创建的视图上获取标签
ReferenceTable的样本数据
Code TableName FieldName EnglishtextforLabel
1 Employee EmployeeId Code
2 Employee EmployeeName Name
3 Employee EmployeeAge Age
作为上面创建视图的示例标签上方的参考表,必须为“给我下面的结果”
:
Code
Name
Age
答案 0 :(得分:0)
只需使用https://stackoverflow.com/a/3723649/9819031 ...,即可在标签中使用FieldName:
# Run the yolo model
out_scores, out_boxes, out_classes = sess.run([scores, boxes, classes], feed_dict={yolo_model.input: image_data,
K.learning_phase(): 0})