Hi anybody
I have two Entities(Asset and Owners). the relationship between them is many to many.
public class Asset
{
[Key]
public int AssetId { get; set; }
public string AssetName { get; set; }
public List<Owners> Owners { get; set; }
}
public class Owners
{
[Key]
public int OwnerId { get; set; }
public string Name { get; set; }
public List<Asset> Assets { get; set; }
}
Ok
I insert three assets that is "Computer", "Table" and "Tablet".
Now, I want insert a new Owner and assign some of the asset that already inserted to it.
I don't want insert a new asset, but also I want only select some asset for any owners that inserted. but I don't understand do it.
using (var context = new MyContext())
{
Owners newOwner = new Owners { Name = "Brad" };
newOwner.Assets = // here must be assign some of assets that already inserted.
context.SaveChanges();
}
thanks