✅ Update or create portfolio EF CORE

I have a venture in my db that has 1 portfolio linked to it (the portfolio is the venture information), Right now I have a API call for venture in which I can alos change the portfolio details, Could/should I make the venture call also be able to add a portfolio if one doesnt exsist already or should I do this in seperate api calls if so how would I go about linking the new portfolio to the venture?
1 Reply
restingphantom
restingphantom3mo ago
c#
[Table("Venture")]
public class Venture
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid? Id { get; set; }

public string Name { get; set; }

public Portfolio? Portfolio { get; set; }
}
c#
[Table("Venture")]
public class Venture
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid? Id { get; set; }

public string Name { get; set; }

public Portfolio? Portfolio { get; set; }
}
c#
[Table("Portfolio")]
public class Portfolio
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid? Id { get; set; }

[Required] public int CoFounders { get; set; }
[Required] public int CoFoundersFemale { get; set; }
[Required] public string CompanyName { get; set; } = null!;
public string? ChamberOfCommerce { get; set; }
public int? Employees { get; set; }
public int? EmployeesFemale { get; set; }
public double? Fte { get; set; }
public double? FteFemale { get; set; }
public string? Market { get; set; }
public int? NumberOfPatents { get; set; }
public string? Problem { get; set; }
[Required] public string QuarterlyHighs { get; set; } = null!;
[Required] public string QuarterlyLows { get; set; } = null!;
public double Revenue { get; set; }
public string? Solution { get; set; }
public string? Website { get; set; }

// Contact Person
[Required] public string ContactFirstName { get; set; } = null!;
[Required] public string ContactLastName { get; set; } = null!;
[Required] public string ContactEmail { get; set; } = null!;
[Required] public string ContactRole { get; set; } = null!;

// Location
[Required] public string Country { get; set; } = null!;
[Required] public string PostalCode { get; set; } = null!;
[Required] public string City { get; set; } = null!;
[Required] public string Address { get; set; } = null!;

// Other tables
public Series? Series { get; set; }
public Industry? Industry { get; set; }
[Required] public Tech1 Tech1 { get; set; } = null!;
public Tech2? Tech2 { get; set; }
public ICollection<Sdg> Sdgs { get; set; } = new List<Sdg>();
public ICollection<Investment> Investments { get; set; } = new List<Investment>();
}
c#
[Table("Portfolio")]
public class Portfolio
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid? Id { get; set; }

[Required] public int CoFounders { get; set; }
[Required] public int CoFoundersFemale { get; set; }
[Required] public string CompanyName { get; set; } = null!;
public string? ChamberOfCommerce { get; set; }
public int? Employees { get; set; }
public int? EmployeesFemale { get; set; }
public double? Fte { get; set; }
public double? FteFemale { get; set; }
public string? Market { get; set; }
public int? NumberOfPatents { get; set; }
public string? Problem { get; set; }
[Required] public string QuarterlyHighs { get; set; } = null!;
[Required] public string QuarterlyLows { get; set; } = null!;
public double Revenue { get; set; }
public string? Solution { get; set; }
public string? Website { get; set; }

// Contact Person
[Required] public string ContactFirstName { get; set; } = null!;
[Required] public string ContactLastName { get; set; } = null!;
[Required] public string ContactEmail { get; set; } = null!;
[Required] public string ContactRole { get; set; } = null!;

// Location
[Required] public string Country { get; set; } = null!;
[Required] public string PostalCode { get; set; } = null!;
[Required] public string City { get; set; } = null!;
[Required] public string Address { get; set; } = null!;

// Other tables
public Series? Series { get; set; }
public Industry? Industry { get; set; }
[Required] public Tech1 Tech1 { get; set; } = null!;
public Tech2? Tech2 { get; set; }
public ICollection<Sdg> Sdgs { get; set; } = new List<Sdg>();
public ICollection<Investment> Investments { get; set; } = new List<Investment>();
}
the name in the venture table is mainly so I could make a copple of ventures for testing porposes