Question

In database present two table

OLD, not EF, modification denied

Object (Id, Name)

UserObjects (Id, UserId, ObjectId)

public class UserObject
{
    [Key]
    public int Id { get; set; }

    public Guid UserId { get; set; }

    public int ObjectId { get; set; }

    [NotMapped]
    public string ObjectName { get; set; }
}

There are way to fill ObjectName with EF?

Or use SqlCommand and fill UserObject manually?

No correct solution

OTHER TIPS

I found and use EntityTypeConfiguration

public class Object
{
    public int Id { get; set; }

    public string Name { get; set; }
}

public class UserObject
{
    [Key]
    public int Id { get; set; }

    public Guid UserId { get; set; }

    public int ObjectId { get; set; }

    public virtual Object Object { get; set; }
}

public class ObjectConfiguration: EntityTypeConfiguration<Object>
{
    public ObjectConfiguration()
    {
        HasKey(at => new { at.Id});

        Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        ToTable("Objects");
        Property(t => t.Id).HasColumnName("Id");
        Property(t => t.Name).HasColumnName("Name");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top