Print Page | Close Window

Custom Association with multiple criteria

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3396
Printed Date: 19-Apr-2024 at 2:10pm


Topic: Custom Association with multiple criteria
Posted By: Vonzkie
Subject: Custom Association with multiple criteria
Date 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






Replies:
Posted By: Vonzkie
Date Posted: 19-Apr-2012 at 2:45am
Correction:

Customer  Invoice
CustomerID =  CustomerID
LocationID   =  InvoiceLocationID 


Posted By: sbelini
Date 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 http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-code-first-tour - DevForce Resource Center for more details in creating CodeFirst Entities/Navigation Properties.
 
Regards,
   Silvio.


Posted By: Vonzkie
Date Posted: 19-Apr-2012 at 4:14pm
Hi,

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

Thanks,
VOn


Posted By: sbelini
Date Posted: 19-Apr-2012 at 4:27pm
 
In model first you mark the properties as Entity Keys and set the Referential Constraint accordingly.
In database first, you will find a solution at http://stackoverflow.com/questions/1545571/how-do-i-make-a-composite-key-with-sql-server-management-studio - http://stackoverflow.com/questions/1545571/how-do-i-make-a-composite-key-with-sql-server-management-studio
 
Silvio.


Posted By: Vonzkie
Date 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


Posted By: sbelini
Date 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.


Posted By: Vonzkie
Date 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


Posted By: sbelini
Date Posted: 24-Apr-2012 at 11:50am
Von,
You might want to take a look at the Code First documentation on details on how to accomplish your objective (if possible):
 
http://msdn.microsoft.com/en-us/data/aa937723 - http://msdn.microsoft.com/en-us/data/aa937723
http://msdn.microsoft.com/en-us/data/hh134698 - http://msdn.microsoft.com/en-us/data/hh134698
http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx - http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx
http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-fluent-api-samples.aspx - http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-fluent-api-samples.aspx
http://social.msdn.microsoft.com/Forums/is/adodotnetentityframework/thread/2cb02baa-0b23-48b3-a529-92d56c6ff7dd - http://social.msdn.microsoft.com/Forums/is/adodotnetentityframework/thread/2cb02baa-0b23-48b3-a529-92d56c6ff7dd
 
I hope this helps.
 
Regards,
   Silvio.


Posted By: Vonzkie
Date Posted: 25-Apr-2012 at 1:35am
Hi Silvio,

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

THanks,
Von


Posted By: sbelini
Date 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.



Print Page | Close Window