Grid.Blazor icon indicating copy to clipboard operation
Grid.Blazor copied to clipboard

CRUD select for Entity

Open walterX12 opened this issue 4 years ago • 2 comments

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

walterX12 avatar Jan 05 '21 10:01 walterX12

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.

gustavnavar avatar Jan 06 '21 18:01 gustavnavar

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

walterX12 avatar Jan 09 '21 09:01 walterX12