many-to-many

Entity Framework many-to-many question

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:08:18
问题 Please help an EF n00b design his database. I have several companies that produce several products, so there's a many-to-many relationship between companies and products. I have an intermediate table, Company_Product, that relates them. Each company/product combination has a unique SKU. For example Acme widgets have SKU 123, but Omega widgets have SKU 456. I added the SKU as a field in the Company_Product intermediate table. EF generated a model with a 1:* relationship between the company and

How to set up a many-to-many relationship in Entity Framework designer thingy

对着背影说爱祢 提交于 2019-11-29 14:03:10
I'm an NHibernate developer trying to give Entity Framework a shot in a hobby project. I'm used to specifying mapping data in code using Fluent NHibernate. Pardoning Microsoft's belief that developers shouldn't be allowed to write code, I'm trying to create my mappings using the Entity Framework's visual designer surface (which you get by opening the .edmx file in Visual Studio). I have no idea how to set up a many-to-many relationship! I have 'updated the model' from the database, but I get two one-to-many relationships with a new entity corresponding to the junction table (which contains

JPA ManyToMany, how can JoinTable have a property?

こ雲淡風輕ζ 提交于 2019-11-29 12:50:41
问题 I have a question for designing the ManyToMany in EJB, how can a jointable has a property? Here is an example, the students and courses are ManyToMany, every student have many courses, and many students choose one course. @Entity public class Student implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; String name; private Collection<Course> courses; @ManyToMany(mappedBy = "students",cascade=CascadeType.ALL) public Collection<Course> getCourses() { return

JPA: which side should be the owning side in a m:n relationship?

半腔热情 提交于 2019-11-29 12:48:39
问题 Say, for example, I had two entities: Article and Tag (like in a typical blog). Each article can have many tags, and each tag can be used by many articles, so it is a classical m:n relationship. I need to specify an owning side with JPA. But which side should be the owning side? An article doesn't depend on a certain tag and vice versa. Is there a rule of thumb for determining which side should be the owning side? 回答1: Every bidirectional relationship requires an owning side in JPA. In the

Core Data Many-to-Many Relationship NSPredicate

ぃ、小莉子 提交于 2019-11-29 12:31:35
I have a data model with a many-to-many relationship like EntityA <-->> EntityB <<--> EntityC . I used to query EntityA with different search criteria and I use NSCompoundPredicate with an array of NSPredicate s. On one of the predicate I wanted to query EntityA using EntityC . I tried to use the following SUBQUERY but it did not work. searchPredicate=[NSPredicate predicateWithFormat:@"(0 != SUBQUERY(EntityB, $B, (0 != SUBQUERY($B.EntityC, $EntityC, $EntityC.name like %@).@count)).@count)", name] And I got the following exception, Terminating app due to uncaught exception

How to have a foreign key pointing to two primary keys?

≯℡__Kan透↙ 提交于 2019-11-29 12:27:58
I'm trying to simplify a database structure, and I have two tables matches and team_statistics : Here in the team_statistics table the team_statistics.team_id should be a foreign key that references matches.teams_id and matches.teams_id1 and similarly team_statistics.group_id should be a foreign key referencing matches.groups_id and matches.groups_id1 How to do this in PostgreSQL? If there are other ways of doing this by having another table between matches and team_statistics I'm open for suggestion, but I would still like to know how to have one foreign key referencing two primary keys.

NHibernate force not-found ignore to not execute an extra select

浪尽此生 提交于 2019-11-29 11:30:33
I'm working with a legacy database where FK's aren't always used. For example I have an entity Person and an entity Country. A person has a Country which is mapped as a many-to-one in the Person mapping. <many-to-one name="Country" class="Country" foreign-key="none" lazy="false" not-found="ignore" fetch="join" outer-join="true" column="countryid"/> When person has null as column value (countryid) it won't perform an extra select query (because it knows that there won't be a reference in the country table), but when a person has 0 as column value NH will perform another select to check the

javax.el.PropertyNotFoundException: Property not found on type org.hibernate.collection.internal.PersistentSet

孤街醉人 提交于 2019-11-29 10:53:44
I try to recuperate data from association ManyToMany but i can't, this is my code. Entity Produit : @Entity public class Produit implements Serializable { @Id @Column(name="Produit_ID") @GeneratedValue private Long id; private String dq; private String icForme; private String ich; private String icht; @ManyToMany(cascade = {CascadeType.ALL}) @JoinTable(name="produit_terminal", joinColumns={@JoinColumn(name="Produit_ID")}, inverseJoinColumns={@JoinColumn(name="Terminal_ID")}) private Set<Terminal> terminals = new HashSet<Terminal>(); //getter setter Entity Terminal : @Entity public class

FindAll with includes involving a complicated many-to-(many-to-many) relationship (sequelizejs)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 10:26:13
问题 This has a sibling question in Software Engineering SE. Consider Company , Product and Person . There is a many-to-many relationship between Company and Product , through a junction table Company_Product , because a given company may produce more than one product (such as "car" and "bicycle"), but also a given product, such as "car", can be produced by multiple companies. In the junction table Company_Product there is an extra field "price" which is the price in which the given company sells

SQL Server Query for Many to Many Relationship

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 10:17:57
I have the following Many to many relationship (See the picture below) in my SQL server. In most cases there's are 2 rows in table tblWavelengths related to the table tblSensors, (in some cases only 1, and in extreme cases there can be 20 rows) I made the following simple query to retrieve the data from those 3 tables : select W.DateTimeID,S.SensorName,S.SensorType,W.Channel,W.PeakNr,W.Wavelength from tblWavelengths as W Left Join tblSensorWavelengths as SW on W.tblWavelengthID = SW.WavelengthID Left Join tblSensors as S on SW.SensorID = S.SensorID order by W.DateTimeID After running this