Ponieważ mój angielski nie jest dobry, po prostu od razu do rzeczy. Dlaczego nagrywanie Firma w bazie danych utworzyć nowy rekord i rekord Klienta odnoszą się do nowego rekordu firmy? Dzięki za pomoc :)Entity Framework - Duplikat rodzica (jednego) podczas tworzenia nowego dziecka (wiele)
public class Company : EntityBase
{
public string Name { get; set; }
public List<Customer> Customers { get; set; }
public List<Invoice> Invoices { get; set; }
}
public class Customer : EntityBase
{
public string Name { get; set; }
public Company Company { get; set; }
public List<Card> Cards { get; set; }
}
public class EFRepositoryBase<TEntity> where TEntity : class, IEntity, new()
{
protected IUnitOfWork UnitOfWork { get; set; }
protected BenzineFleetContext Context
{
get { return (BenzineFleetContext) UnitOfWork; }
}
public virtual DbSet<TEntity> GetDbSet<TEntity>() where TEntity : class
{
return Context.Set<TEntity>();
}
public virtual void Add(TEntity entity)
{
GetDbSet<TEntity>().Add(entity);
}
public virtual void SaveChanges()
{
Context.SaveChanges();
}
}
//Save
var cus = new klienta {Spółka = SelectedCompany}
_srv.Add(cus);
_srv.SaveChanges();
Istnieje kilka relacji i innych rzeczy, może ... Czy możesz jasno określić, co dokładnie chcesz zrobić? –
Chcę utworzyć nowego klienta, customer.Company = Wybrana firma z bazy danych – yovierayz