У меня есть некоторые проблемы с. net основной сущностью при получении данных.
это мой код контроллера
_context.Hierarchies
.Include(i => i.Children)
.AsEnumerable()
.Where(x => x.Parent == null)
.ToList();
и это мой класс модели
public class Hierarchy
{
public Hierarchy()
{
CreatedDate = DateTime.UtcNow;
Children = new List<Hierarchy>();
}
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public User CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
public Organization Organization { get; set; }
public List<Task> Tasks{ get; set; }
public Hierarchy Parent { get; set; }
public long? ParentId { get; set; }
public List<Hierarchy> Children { get; set; }
}
и это мой построитель модели контекста БД
modelBuilder.Entity<Hierarchy>(hierarchy => {
hierarchy.HasMany(c => c.Children)
.WithOne(c => c.Parent)
.HasForeignKey(c => c.ParentId);
});
При вызове мой API-результат будет
[
{
"id": 16,
"name": "category1",
"description": null,
"createdBy": {
"id": 2,
"email": "test@test.com",
"passwordHash": "IR4uM8YiGpzevGjNYQHfFgFBkHqTqGy3rgCsA8d9LNZAmTItvy2l3MXSnPcXQD7QldV3X5GA/CKSF4mPCFkAYg==",
"passwordSalt": "XWzpfAf8IA7wpgY+gtVHiGPxTX4avvn38VY7MFspMhAfPUwL1a9ctuSQcEPlRJKqfK/3yZRtPWUlMQV7XH0JHRd4bKFvH/NKpSr4v46vOlgdQWAZDH1dklmqPtCmYK/Rq8SC/qcKfrmQLbJewBJ7B1Fse33ohAXp29+0K1c4YsE=",
"name": null,
"avatar": null,
"address": null,
"aboutMe": null,
"company": null,
"job": null,
"city": null,
"country": null,
"birthday": "0001-01-01T00:00:00",
"createdDate": "2020-04-08T02:38:40.288739",
"userOrganizations": null,
"ownerTasks": null,
"assignedTasks": null,
"assigneeTasks": null,
"currentOrganization": {
"id": 2,
"name": "Default",
"description": "",
"createdDate": "2020-04-07T23:38:40.459297",
"userOrganizations": [],
"hierarchies": [
{
"id": 17,
"name": "category2",
"description": null,
"createdDate": "2020-04-08T02:09:46.1474742Z",
"tasks": [],
"parentId": 16,
"children": []
}
]
}
},
"createdDate": "2020-04-08T02:09:34.54658",
"organization": {
"id": 2,
"name": "Default",
"description": "",
"createdDate": "2020-04-07T23:38:40.459297",
"userOrganizations": [],
"hierarchies": [
{
"id": 17,
"name": "category2",
"description": null,
"createdBy": {
"id": 2,
"email": "test@test.com",
"passwordHash": "IR4uM8YiGpzevGjNYQHfFgFBkHqTqGy3rgCsA8d9LNZAmTItvy2l3MXSnPcXQD7QldV3X5GA/CKSF4mPCFkAYg==",
"passwordSalt": "XWzpfAf8IA7wpgY+gtVHiGPxTX4avvn38VY7MFspMhAfPUwL1a9ctuSQcEPlRJKqfK/3yZRtPWUlMQV7XH0JHRd4bKFvH/NKpSr4v46vOlgdQWAZDH1dklmqPtCmYK/Rq8SC/qcKfrmQLbJewBJ7B1Fse33ohAXp29+0K1c4YsE=",
"name": null,
"avatar": null,
"address": null,
"aboutMe": null,
"company": null,
"job": null,
"city": null,
"country": null,
"birthday": "0001-01-01T00:00:00",
"createdDate": "2020-04-08T02:38:40.288739",
"userOrganizations": null,
"ownerTasks": null,
"assignedTasks": null,
"assigneeTasks": null
},
"createdDate": "2020-04-08T02:09:46.1474742Z",
"tasks": [],
"parentId": 16,
"children": []
}
]
},
"tasks": null,
"parent": null,
"parentId": null,
"children": [
{
"id": 17,
"name": "category2",
"description": null,
"createdBy": {
"id": 2,
"email": "test@test.com",
"passwordHash": "IR4uM8YiGpzevGjNYQHfFgFBkHqTqGy3rgCsA8d9LNZAmTItvy2l3MXSnPcXQD7QldV3X5GA/CKSF4mPCFkAYg==",
"passwordSalt": "XWzpfAf8IA7wpgY+gtVHiGPxTX4avvn38VY7MFspMhAfPUwL1a9ctuSQcEPlRJKqfK/3yZRtPWUlMQV7XH0JHRd4bKFvH/NKpSr4v46vOlgdQWAZDH1dklmqPtCmYK/Rq8SC/qcKfrmQLbJewBJ7B1Fse33ohAXp29+0K1c4YsE=",
"name": null,
"avatar": null,
"address": null,
"aboutMe": null,
"company": null,
"job": null,
"city": null,
"country": null,
"birthday": "0001-01-01T00:00:00",
"createdDate": "2020-04-08T02:38:40.288739",
"userOrganizations": null,
"ownerTasks": null,
"assignedTasks": null,
"assigneeTasks": null,
"currentOrganization": {
"id": 2,
"name": "Default",
"description": "",
"createdDate": "2020-04-07T23:38:40.459297",
"userOrganizations": [],
"hierarchies": []
}
},
"createdDate": "2020-04-08T02:09:46.1474742Z",
"organization": {
"id": 2,
"name": "Default",
"description": "",
"createdDate": "2020-04-07T23:38:40.459297",
"userOrganizations": [],
"hierarchies": []
},
"tasks": [],
"parentId": 16,
"children": []
}
]
}
]
он будет создан createBy -> currentOrganization -> иерархия
мне не нужно currentOrganization и иерархия, также объект createBy имеет пароль пользователяHa sh
как я могу настроить свое возвращаемое значение;