Entity Framework Code First

0

When I work with code first when I have a navigation property and work with Map, is that navigation property just for the code?

Another question, my primary key is a ProviderId string, how do I tell EF that my PK is not identity?

public class Proveedor
{
    public string ProveedorId { get; set; }
    public string RazonSocial { get; set; }
    public string RUC { get; set; }
    public string DNI { get; set; }
    public string Direccion { get; set; }
    public string Fijo { get; set; }
    public string Celular { get; set; }
    public string Representante { get; set; }
    public string Email { get; set; }

    public ICollection<Producto> Productos { get; set; }

}

Map

public class ProveedorMap : EntityTypeConfiguration<Proveedor>
{
    public ProveedorMap()
    {
        ToTable("Proveedores");
        HasKey(c => c.ProveedorId);
        Property(c => c.ProveedorId).IsRequired().HasMaxLength(6).HasColumnOrder(0)
        Property(c => c.RazonSocial).IsRequired().HasMaxLength(200).HasColumnOrder(1);
        Property(c => c.RUC).HasMaxLength(11).HasColumnOrder(2);
        Property(c => c.DNI).HasMaxLength(8).HasColumnOrder(3);
        Property(c => c.Direccion).HasMaxLength(100).HasColumnOrder(4);
        Property(c => c.Fijo).HasMaxLength(9).HasColumnOrder(5);
        Property(c => c.Celular).HasMaxLength(9).HasColumnOrder(6);
        Property(c => c.Representante).HasMaxLength(100).HasColumnOrder(7);
        Property(c => c.Email).HasMaxLength(100).HasColumnOrder(8);

    }
}

The navigation property does not go in MapMap.

    
asked by Pedro Ávila 01.04.2016 в 01:50
source

1 answer

1

> > when I have a navigational property and I work with Map that navigation property is only for the code?

I imagine you mean the definition of the properties that lists the products, in that case you would have

 public class Producto {

      public int ProductoId { get; set; }

      //resto propiedades

      public string ProveedorId { get; set; }
      public Proveedor Proveedor{ get; set; }

 }

Those ProviderId property that allow you to join in a relation uno a mucho if they are only for the Id

but the property

 public ICollection<Producto> Productos { get; set; }

of the class Proveedor that will contain the entities of the complete products

> > > > my primary key is a ProviderId string, how do I tell EF that my PK is not identity?

You can not, it is more try to do this in the database, you will see that the fields that you want to define as identity can only be numeric

> > The navigation property does not go in MapMap.

If you can also define it

[Entity Framework] [Code First] One to many partnership (1 / 3)

for that you use the HasRequired or HasOptional as I explain in the article

    
answered by 01.04.2016 / 02:57
source