public static bool InsertMediaSource(long eventId, string channelName) { ArtAuctionDatabase db = new ArtAuctionDatabase();s AuctionEventRow row = db.AuctionEventTable.Where(p => p.AuctionEventId == eventId).FirstOrDefault(); if (row == null) return false; if (row.CurMediaSource == null) row.CurMediaSource = string.Empty; string temp = row.CurMediaSource; if (temp.IndexOf(channelName) >= 0) return true; string[] channels = temp.Split(';'); //求并 string[] newChannels = channels.Union(new string[] { channelName }).ToArray(); //类似javascript join()方法,参数为Func类型 row.CurMediaSource = newChannels.Aggregate((item, nextItem) => item + ";" + nextItem); db.SubmitChanges(); return true; } public static bool DeleteMediaSource(long eventId, string channelName) { ArtAuctionDatabase db = new ArtAuctionDatabase(); AuctionEventRow row = db.AuctionEventTable.Where(p => p.AuctionEventId == eventId).FirstOrDefault(); if (row == null) return false; string temp = row.CurMediaSource; if (temp.IndexOf(channelName) == -1) return true; string[] channels = temp.Split(';'); //求差 string[] newChannels = channels.Except(new string[] { channelName }).ToArray(); if (newChannels.Length == 0) row.CurMediaSource = ""; else row.CurMediaSource = newChannels.Aggregate((item, nextItem) => item + ";" + nextItem); db.SubmitChanges(); return true; }