hi,I am using a model with Code First, and I have a relationship between two tables 1: N.
I have classes: Person and computer.
Public Class Computer Property Id As Integer Property Idperson As System.Nullable(Of Integer)
Overridable Property person As PersonEnd Class
Public Class Person Property Id As Integer Property Name As String Property LastName As Stringh
Overridable Property Computers As List(Of Computer)End Class
Public Class DbMyModel Inherits DbContext
Property Persons As DbSet(Of Person) Property Computers As DbSet(Of Computer)
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder) MyBase.OnModelCreating(modelBuilder) modelBuilder.Configurations.Add(New ComputerConfiguracion) End Sub
End Class
Public Class ComputerConfiguracion Inherits EntityTypeConfiguration(Of Computer)
Sub New() HasOptional(Function(o) o.person).WithMany(Function(n) n.computers).HasForeignKey(Function(o) o.Idperson) End SubEnd Class
Namespace Mvc4Ejemplo Public Class TestController Inherits System.Web.Mvc.Controller
Private db as new DbMyModel
<GridDataSourceAction> _ <ActionName("PagingGetData")> _ Public Function Index() As ActionResult Return View(db.Computers.ToList.AsQueryable) End Function
End ClassEnd Namespace
@Imports Infragistics.Web.Mvc@ModelType IQueryable(of Mvc4Ejemplo.Computer)@Code ViewData("Title") = "Index"End Code@Section Scripts <link href="~/Scripts/jQuery/Common/CSS/structure/modules/infragistics.ui.grid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="~/Scripts/jQuery/jquery-1.7.1.js" type="text/javascript"></script> <script src="~/Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"></script> <script src="~/Scripts/jquery-ui-1.8.20.js" type="text/javascript"></script> <script src="~/Scripts/jQuery/Common/js/infragistics.loader.js" type="text/javascript"></script> <script src="~/Scripts/jQuery/Common/js/infragistics.js" type="text/javascript"></script>
@Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr")
End Section
<div id="content">
@(Html.Infragistics().Grid(Model).ID("grid1").PrimaryKey("ID") _ .AutoGenerateColumns(True) _ .Features(Sub(features2) features2.Paging() features2.Selection.Mode(SelectionMode.Row).MultipleSelection(False) features2.Updating() _ .EnableAddRow(True).AddRowLabel("Añadir nueva fila") _ .EnableDeleteRow(False) _ .EditMode(GridEditMode.Row) _ .ColumnSettings(Sub(setting) setting.ColumnSetting().ColumnKey("ID").ReadOnly(True) End Sub) End Sub).Width("705").Height("500") _ .DataSourceUrl(Url.Action("PagingGetData")).DataBind().Render())
</div>
Give a problem with DynamicProxies model.With this type of model, is the infragistics grid I can display the model?I need that when you find navigation properties, show me Overrides toString Object.And then I would like to edit a row, you can access the navigation property that references to in order to change it.By this I mean, when I want to edit the row, leave all fields as usual, but the property of the class Person Computer, is, for example, a button, and pressing it and do what I need.
Thanks in advance.
Best regards.
Hi Angel,
The problem I told you about earlier just fix it.What happened to me, if you have seen code first, that they were leaving the data context, navigation variables lost their reference.I had stopped this issue, so I just look at it and understand why I did this type of error.Trying to access the navigation variables and their properties, when they no longer have data that are not in the context.
Thanks for all.
Best Regards.
Hi,
I am not sure I fully understand the issues you are facing. Is the grid loading correctly ? Other than that, yes, you can customize rows by using a column or a row template:
http://ko.infragistics.com/products/jquery/sample/grid/basic-column-template
If you can provide more information, or even better, some sample app which contains all your logic, that would greatly help.
Thanks,
Angel