swagger 忽略 ComplexItems 属性。我需要为我的客户端应用程序生成 axios 模型。
public class DummyModel
{
[Key]
public Guid Id { get; set; }
[Required]
public string Name { get; set; }
// This is your complex list
public List<ComplexItem> ComplexItems { get; set; } = new List<ComplexItem>();
}
public class ComplexItem
{
[Key]
public Guid Id { get; set; }
public int Property1 { get; set; }
public string Property2 { get; set; }
public DateTime Property3 { get; set; }
}
在 Api 上下文中我添加了关系。
modelBuilder.Entity<DummyModel>()
.HasMany(dm => dm.ComplexItems)
.WithOne() // or WithMany() based on your needs
.HasForeignKey("ForeignKeyColumnIfAny");
在控制器中我添加了包括:
return await _context.DummyModels
.Include(dm => dm.ComplexItems)
.ToListAsync();
但是没有 list 属性的模型看起来像这样:
export interface DummyModel {
/**
*
* @type {string}
* @memberof DummyModel
*/
id?: string;
/**
*
* @type {string}
* @memberof DummyModel
*/
name: string;
}