New Posts New Posts RSS Feed: Custom Association with multiple criteria
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Custom Association with multiple criteria

 Post Reply Post Reply
Author
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Topic: Custom Association with multiple criteria
    Posted: 19-Apr-2012 at 2:44am
Hi,

How can I create a custom association in Devforce that have multiple criteria?

E.g: 

Customer
CustomerID
Name
LocationID

Invoice
InvoiceID
CustomerID
Description
InvoiceLocationID

I want to have a one to many relationship with Customer and Invoice but the criteria would be:

Customer  Invoice
CustomerID =  CustomerID
LocationID   =  LocationID

How can I do that?

Thanks,
Von



Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 2:45am
Correction:

Customer  Invoice
CustomerID =  CustomerID
LocationID   =  InvoiceLocationID 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 12:22pm
Hi Vonzkie,
 
Are you talking about Code First?
 
If that's the case you must set the order of the PK when working with composite keys:
 
Column("CustomerID", Order=0)]
 
You can check our Code First samples in the DevForce Resource Center for more details in creating CodeFirst Entities/Navigation Properties.
 
Regards,
   Silvio.
Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 4:14pm
Hi,

I'll try to look at it. :)
How about not Code First?

Thanks,
VOn
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 4:27pm
 
In model first you mark the properties as Entity Keys and set the Referential Constraint accordingly.
 
Silvio.
Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 22-Apr-2012 at 11:31pm
Hi Silvio,

That works for us.
However, since let's say for example I have my table marked 2 of its column as Entity Key and tried to associate it again with another table but I don't need the criteria being map to the other column. How would I do it?

Thanks,
Von
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2012 at 10:09am
Von,
 
Not sure I understand the question.
You are trying to associate 2 tables, but don't want to use the PK_FK association?
 
Please clarify.
 
Silvio.
Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2012 at 5:45pm
Hi Silvio,

Here's the original problem that we solved.

Customer
CustomerID
Name
LocationID

Invoice
InvoiceID
CustomerID
Description
InvoiceLocationID

I want to have a one to many relationship with Customer and Invoice but the criteria would be:

Customer  Invoice
CustomerID =  CustomerID
LocationID   =  LocationID

Now, what about adding another table and link it with Customer such as CustomerDetails

CustomerDetails
DetailID
Description
CustomerID

How do I associate this to Customer by bypassing the LocationID because I don't need it in this association.

Thanks,
Von
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 24-Apr-2012 at 11:50am
Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Posted: 25-Apr-2012 at 1:35am
Hi Silvio,

Would that be possible with Database First Design? Are there some workarounds?

THanks,
Von
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 26-Apr-2012 at 2:50pm
Hi Von,
 
You won't be able to create an association where the FK is part of a composite key. Since it's just a FK you better off simply adding it to your CustomerDetails entity.
 
Since this is more of a design question I think you'd benefit more from our Professional Services Team assistance.
Let me know if this interests you, so I can have someone get in touch with you in this regard.
 
Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down