C
C#9mo ago
Klepsi

how to embed?

I need to embed these objects in this large object
[Collection("warehouse.transactions")]
public class Transaction
{
public ObjectId id { get; set; } = ObjectId.GenerateNewId();
[Required]
public DateTime Time { get; set; } = DateTime.UtcNow;

[Required]
public double Amount { get; set; }

[Required]
public Item? Item { get; set; }

[Required]
public Warehouse? Warehouse { get; set; }

[Required]
public Buyer? Buyer { get; set; }

[Required]
public Staff? Staff { get; set; }
}
[Collection("warehouse.transactions")]
public class Transaction
{
public ObjectId id { get; set; } = ObjectId.GenerateNewId();
[Required]
public DateTime Time { get; set; } = DateTime.UtcNow;

[Required]
public double Amount { get; set; }

[Required]
public Item? Item { get; set; }

[Required]
public Warehouse? Warehouse { get; set; }

[Required]
public Buyer? Buyer { get; set; }

[Required]
public Staff? Staff { get; set; }
}
but I keep getting errors about shadow properties (EntityFramework 7 Mongodb) how would I do this?
1 Reply
Klepsi
KlepsiOP9mo ago
I did a thing where I just separate core values from the ID and it worked example:
using System.ComponentModel.DataAnnotations;
using MongoDB.Bson;
using MongoDB.EntityFrameworkCore;

namespace PawelApp.Data;


public class Item
{
[Required]
public ItemType ItemType { get; set; }
[Required]
public Price? Price { get; set; }
[Required]
public string? Name { get; set; }
public string? Description { get; set; }
}
[Collection("items")]
public class ItemWithId : Item
{
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();

}
using System.ComponentModel.DataAnnotations;
using MongoDB.Bson;
using MongoDB.EntityFrameworkCore;

namespace PawelApp.Data;


public class Item
{
[Required]
public ItemType ItemType { get; set; }
[Required]
public Price? Price { get; set; }
[Required]
public string? Name { get; set; }
public string? Description { get; set; }
}
[Collection("items")]
public class ItemWithId : Item
{
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();

}
Want results from more Discord servers?
Add your server