I'm working on an application for printers auditing. So, when an user choose a printer name, he could see all the users which are related to it. This is my database model : 

[![enter image description here](https://i.stack.imgur.com/vl648.jpg)](https://i.stack.imgur.com/vl648.jpg)

I'm thinking about built a little script for sending user name account, pc name, list of printers and the datetime to a WCF service from user's PCs. Then a WCF service could upload these info in database. 

But... I have a problem to understand how I could create a new record with a one to many relationship.

```
public void AuditRecord(DateTime date,String user,string[] printer, String pc)
{
var USR = new Users ()
{
    UserName = user,
};

var PC = new Pc()
{
    PcName = pc,
};

var PTR = new Printers();
List<Printers> ptr = new List<Printers>();
for (int i = 0;i<printer.Count;i++)
{
    ptr.Add(new Printers
    {
        PrinterName= printer[i],
    });
}

var REF = new Reference()
{
Date = date,
};

context.SaveChanges(); }

```

EDIT :

With this solution it's working for insertion.

```
ptr.ToList().ForEach(p=>
{
    var RF = new Reference() {Date=DateTime.Now};
    var USR = new Users() {UserName=user};
    var PC = new Pc() {PcName=pc};
    var PTR = new Printers() {PrinterName = p };
    PTR.Reference.Add(RF);
    USR.Reference.Add(RF);
    PC.Reference.Add(RF);
    context.Pc.Add(PC);
    context.Users.Add(USR);
    context.Printers.Add(PTR);
});
context.SavesChanges();

```

But I have a problem in reference table. If an user use three printers, I need to insert the Id's for each printer and the same Id's for User and Pc. Like this

```
Date     | PrinterId | UserId | PcId
17/11/15        1         1       1
17/11/15        2         1       1
17/11/15        3         1       1

```

And I have :

```
Date     | PrinterId | UserId | PcId
17/11/15        1         1       1
17/11/15        2         2       2
17/11/15        3         3       3

```