0
votes

I'm having trouble with multiple insert row with linq. i have 2 tables,,

[Subscribe] Table

enter image description here

and [Message] Table

  • MessageID (int, isIdentity)
  • Sender
  • Receiver
  • Content

i want all UserName in Subcribe table which subcribe to "Rock" Category receive one same Messages from me.. my codes now is giving an error

    var subcribe = from s in database.Subscribes
                   where s.SubscribeCategory == "Rock"
                   select s.UserName;


    foreach (string s in subcribe)
    {
        Message msg = new Message();
        msg.MsgContent = "Text Here";
        msg.Sender = this.User.Identity.Name;
        msg.Receiver = s;
        database.Messages.InsertOnSubmit(msg);
    }
    database.SubmitChanges();

can anyone help with this query? thanks before..

Regards..

1
Can you include the error please?Alex Wilson
@yuma What's the error ?Priyank Patel
@irsog that case is different; that poster made the mistake of not instantiating a new item for each iteration.McGarnagle
what's the error you get(after runing)?KF2

1 Answers

2
votes

I can see that you haven't set the primary key column in the Message table so there may be a chance that you are getting this error:

Can't perform Create, Update or Delete operations on Table(Message) because it has no primary key.

For that you have to add a primary key in the Message table and then refactor the DataClasses.dbml.