Reputation: 51
I'm having trouble with multiple insert row with linq. i have 2 tables,,
[Subscribe] Table
and [Message] Table
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..
Upvotes: 0
Views: 2076
Reputation: 17194
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
.
Upvotes: 2