剑道网格填充和岗位的所有导航属性 [英] Kendo Grid populates and posts all of the navigation properties
问题描述
我有一个使用串口
类作为其模型剑道UI网格。这个类有与行
类的关系,但我并不在我的网格使用任何导航属性的,我不需要他们在这个特殊的页面。
问题是,剑道UI填充所有的外键关系。因此,行
类和所有自身的导航属性将被填充。当我尝试保存我的编辑,剑道所有帖子这些数据,这将导致 ModelState.IsValid
永远是假
。你有什么建议吗?
这是串口
类,我有一个字段为每个属性。
公共类系列
{
[键]
[专栏(类型名=BIGINT,令= 0)]
公众的Int64 LiIdR {搞定;组; }
[ForeignKey的(LiIdR)]
公共虚拟行排{搞定;组; } [关键词,DatabaseGenerated(DatabaseGeneratedOption.Identity)
公众的Int16 SRadifS {搞定;组; }
公共字符串AFromSerial {搞定;组; }
公共字符串AToSerial {搞定;组; }
公众诠释? IQnty {搞定;组; }
公共字符串AExpireDate {搞定;组; }
公共字符串AComment {搞定;组; }
}
这通常是一个不好的做法,用在您的视图生成的实体框架的对象。您认为不应依赖数据访问层上。
你应该做的是转换的EF实体到视图模型(包含网格只需要什么)的业务/数据层。这将解决您的问题。
在编辑/创建你只是转换视图模型回一个EF对象,将更改保存到数据库中。
如果由于某种原因,你需要查看你不希望展现给用户一定的属性,可以将它们添加到网格为隐藏()
列。然后,他们会得到回发到控制器。
I have a Kendo UI Grid which uses the Serial
class as its model. This class has relation with the row
class, but I don't use any of the navigation properties in my Grid and I don't need them in this particular page.
The problem is, Kendo UI populates all of the foreign key relations. So the row
class and all of the navigation properties of itself will be populated. When I try to save my edit, Kendo posts all of these data and this causes ModelState.IsValid
always be false
. Do you have any suggestion?
This is the Serial
class, and I have a field for each property.
public class Serial
{
[Key]
[Column(TypeName = "BIGINT", Order = 0)]
public Int64 LiIdR { get; set; }
[ForeignKey("LiIdR")]
public virtual Rows Row { get; set; }
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Int16 SRadifS { get; set; }
public string AFromSerial { get; set; }
public string AToSerial { get; set; }
public int? IQnty { get; set; }
public string AExpireDate { get; set; }
public string AComment { get; set; }
}
It's generally a bad practice to use the generated Entity Framework objects in your view. Your view should not be dependent on the data access layer.
What you should do is to convert the EF entities into view models (containing only what your grid needs) in your business/data layer. This will solve your issue.
On edit/create you just convert the view model back into a EF object and save your changes to the database.
If, for some reason, your view needs certain properties which you don't want to show to the user, you can add them to the grid as Hidden()
columns. Then they'll get posted back to the controller.
这篇关于剑道网格填充和岗位的所有导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!