0

I am very new to code first. I have tried reading as much as I can but I have not found an answer to my question. When using object composition and code first how do you create a composite key. for example

    public class Foo
    {
     public FooID {get; set;}
     public FooName {get; set;}
    }
    public class Bar
    {
    public virutal Foo {get; set;}
    public BarID {get; set;}
    public BarName {get; set;}
    }

How can I make sure in the DB schema that FooID and BarID are composite keys?

Also should I even do the virtual Foo? *or should create bar like this?* If I use the below bar implementation is there a way of being able to use statements like this bar.foo.name (i doubt it but maybe EF does some cool magic to let this happen)?

Public Class Bar
{
public FooID {get; set;}
public BarID  {get; set;}
public BarName {get; set;}
}

IF possible I would like to be able to do all that through data annotations. Thank you very much

gh9
  • 10,169
  • 10
  • 63
  • 96
  • http://stackoverflow.com/questions/5436731/composite-key-as-foreign-key answer to my question! – gh9 Feb 28 '12 at 02:22

1 Answers1

0

composite key as foreign key

Answered the question. Posting this as a answer to be more visible to other people needing this information.

Community
  • 1
  • 1
gh9
  • 10,169
  • 10
  • 63
  • 96