Grid.Blazor
Grid.Blazor copied to clipboard
CRUD select for Entity
Hi,
thank you very much for very useful Grid. I have started to use it on my project and I am wondering if there is a way to implement select in CRUD without having "Id" in the domain model class ? Is there a way how to enable CRUD select with domain model like below ( Person has direct reference to the Car object ) ?
public class Car
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Car CarModel { get; set; } // <-------- I would like to have reference to the Car itself here
}
All documented examples relies on Id property defined for Foreign key and it woks fine. E.g the sample from the issue https://github.com/gustavnavar/Grid.Blazor/issues/37 there is CarId in the domain class Person:
public class Car
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Guid CarId { get; set; }
}
Regards
You can use a model referencing both the Car object and the foreign key:
public class Car
{
[Key]
public Guid Id { get; set; }
public string Name { get; set; }
}
public class Person
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public Guid CarId { get; set; }
[ForeignKey("CarId")]
public virtual Car CarModel { get; set; }
}
This is the type of models that I use in projects for my clients.
Hi Gustav,
thank you for your hint. I know suggested approach will work, but it is not feasible(cost effective) for some projects to update base model domain classes. I am thinking of some "enhanced" class SelectItem like
public class SelectItemGeneric<T>
{
public const string ListFilter = "ListFilter";
public T Value { get; set; }
public string Title { get; set; }
public SelectItemGeneric(T value, string title)
{
Value = value;
Title = title;
}
}
I am aware that it would lead to many changes, but is there a chance to add something like this to a "feature wish list" ?
Regards