Hi Kamyab Faghih,
You could use repeated
to define one-to-many field in proto files. Such as following:
Protos/Service1.proto
syntax = "proto3";
option csharp_namespace = "WebApplication310.Protos";
service Service1 {
rpc GetOrder(OrderRequest) returns (Order);
}
message OrderRequest{
int32 orderId =1;
}
message Order {
int32 orderId = 1;
repeated Item items=2;
}
message Item {
int32 id = 1;
string name = 2;
}
Then you could make use the Order entity like following:
MyService.cs
public class MyService : WebApplication310.Protos.Service1.Service1Base
{
public override Task<Order> GetOrder(OrderRequest request, ServerCallContext context)
{
var items = new List<Item>
{
new Item { Id = 1, Name = "Apple" },
new Item { Id = 2, Name = "Orange" }
};
return Task.FromResult(new Order
{
OrderId = request.OrderId,
Items = { items }
});
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.