Let's say I have the following code:

```
public class TenantId
{
   public Guid Id { get; protected set; }

   public TenantId(Guid id)
   {
      Id = id;
   }
}

public class Tenant
{
   public TenantId Id { get; protected set; }
   public string Name { get; set; }

   public Tenant(TenantId id, string name)
   {
      Id = id;
      Name = name;
   }
}

```

Is there a way to map TenantId as a Guid primary key in Entity Framework Code First?

I have tried the following:

```
modelBuilder.Entity<Tenant>()
   .HasKey(m => m.Id );

```

and

```
modelBuilder.Entity<Tenant>()
   .HasKey(m => m.Id.Id );

```

Both compile, but both throw runtime exceptions. The former says it's an invalid type (must be a scalar, string or byte[]). The latter complains about an invalid expression, for not being a property.

I also tried adding an implicit conversion from TenantId to Guid, with no luck,