I am having problems storing data in a database using EF. Normally, all CRUD operations work fine for the rest of the program, but I recently noticed that in the case of the m: n relationship, the hard part arises.
I am using EF4.1 with the first code approach. The interesting parts of my classes are as follows:
public class Publication : IItem, IDataErrorInfo {
...
[InverseProperty("Publications")]
public virtual ICollection<Group> Groups{ get; set; }
}
public class Group : IItem, IDataErrorInfo {
...
[InverseProperty("Groups")]
public virtual ICollection<Publication> Groups{ get; set; }
}
The database is created as follows:
public PublicationsDB() : base("PublicationDB") {
this.Configuration.AutoDetectChangesEnabled = true;
}
public DbSet<Publication> Publications { get; set; }
public DbSet<Software> Softwares { get; set; }
public DbSet<Group> Group{ get; set; }
The goal is to create an m: n relationship between publications and groups.
XML, . , ICollection, SaveChanges(). ( ), ICollection.
:
:
- ,
ICollection<Group>, xml - .
ICollection<Publication> null.
? . , : DBSet<Groups> . , A B, A.ICollection = null and B.ICollection.Count =1 (which is by the way wrong), , .. A.ICollection = null and B.ICollection = null (which is also wrong)
?
? ? ?:)
, .
Publication (m):(n) Group - Publication (m):(1) NewEntityRelation (n):1 Group, , .
.