[英]Read Maximum length of Entity Framework field and assign to textbox in Razor View
I want to map each field the user enters data into correlates with a database field that can easily set by reading database table definition and set it manually in razor view by setting maximum or in my view model but I need to make it dynamic if Database administrator change the maximum character limit through SQL server it will automatically update the maximum limit of character in text field. 我想映射用户输入数据的每个字段与可以通过读取数据库表定义轻松设置的数据库字段相关联,并通过设置最大值或在我的视图模型中在razor视图中手动设置它,但是如果数据库管理员需要将其动态化通过SQL Server更改最大字符数限制,它将自动更新文本字段中的最大字符数限制。 I am trying to read it from Entity framework and set it in razor view.
我试图从实体框架中读取它,并将其设置在剃刀视图中。 Is this possible to make it dynamic in any way.
这有可能以任何方式使其动态化吗?
And how can I read max length field from razor view. 以及如何从剃刀视图读取最大长度字段。
After further search I figure out how to read maximum length of field from Entity Framework Schema 经过进一步的搜索后,我弄清楚了如何从Entity Framework Schema中读取最大字段长度
public void read()
{
using (var db = new PortalContext())
{
var objectContext = ((IObjectContextAdapter)db).ObjectContext;
var container = objectContext.MetadataWorkspace.GetEntityContainer(objectContext.DefaultContainerName, DataSpace.CSpace);
int maxLength = (int)container.EntitySets["Customers"].ElementType.Properties["LastName"].MaxLength;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.