English 中文(简体)
linq 创建关系的问题
原标题:linq issue with creating relationships

Seems 我对我的林克稍有问题,我有一组数据合同,我有适当的信息合同。 信息可以成为小组的一部分。 然而,当我更新信息记录时,我没有在小组信息清单中反映这一信息时,这一信息对该集团来说仍然是一样的。 但是,在我直接列出信息时,最新情况还是反映了?

这就是我如何向一个团体发出信息:

    //lists for reference:
    List<Group> Groups = new List<Group>();
    List<Message> messages = new List<Message>();

    //not sure the below method is correct for adding a message to a group
    public void AddMessagetoGroup(string group, string messageID, string message)
    {
        var result = Groups.Where(n => String.Equals(n.GroupName, group)).FirstOrDefault();
        var result1 = messages.Where(n => String.Equals(n.MessageID, messageID)).FirstOrDefault();
        if (result != null)
        {
            result.GroupMessages.Add(new Message() { MessageID = messageID, GroupMessage = message });
        }
        if (result1 != null)
        {
            result1.MessageGroup.Add(new Group() { GroupName = group });
        }

    }

如果我向小组传达我对电文作出的任何改动,我就应认真理解正在发生什么。 我认为的唯一事情是,它增加了一个新例子,说明已经存在的信息,这意味着我的更新方法只是复制这一信息,但即便是在哪里,这一新的复制记录也得到保存。 如果难以确定如何更新已经复制的信息,我就能够更新这些信息。 而是对小组的增益(工作周期)?

最佳回答

假设一个小组能够有电文和电文,可以有团体,那么你正试图维持5件事:

  1. The list of all Groups List<Group> Groups = ...
  2. The list of all Messages List<Message> messages = ...
  3. The messages for each Group List<Message> GroupMessages... in Group
  4. The groups for each message List<Group> MessageGroup... in Message
  5. The actual message to send to the group updated in several places

从我能看到的最后一点来看,没有正确保持:

  • http://www.un.org/Depts/DGACM/index_french.htm 这是一班的新例子,在你更新其他电文时自动更新。 仅因为两条电文相同<代码>。 信电灯()并不意味着它们是相同的。

  • 在<代码>UpdateMessage中,你改动了某一特定信息,但仅限于电文清单中。 这并不意味着集团名单上的同样信息。

毕竟,你们需要再次证明,你们的法典真正符合你们想要的。 我看到的是,你想要把团体和信息分开,一劳永逸地提及,而不是制造复制件。

第一,总清单:

List<Group> Groups = new List<Group>();
List<Message> Messages = new List<Message>();

第二,创建<>or,更新信息(目前尚未建立部分):

public Message CreateOrUpdateMessage(string messageID, string groupMessage)
{
    var findmessage = Messages.Where(s => s.MessageID == messageID).FirstOrDefault();

    if (findmessage != null)
    {
        findmessage.GroupMessage = groupMessage;
    }
    else
    {
        findmessage = new Message() { MessageID = messageID, GroupMessage = groupMessage};
        Messages.Add(findmessage);
    }

    return findmessage;
}

Note how this takes care of adding this message to the Messages list. This is the only function that should add or change messages.

最后向一个团体添加信息(注一对在这里增加团体不抱担忧):

public void AddMessagetoGroup(string group, string messageID, string message)
{
    var findmessage = CreateOrUpdateMessage(messageID, message); 
    var findgroup = Groups.Where(n => String.Equals(n.GroupName, group)).FirstOrDefault();

    if (findgroup != null)
    {
        if (findgroup.GroupMessages.Where(m => m.MessageID == messageID).Count() == 0)
        {
            findgroup.GroupMessages.Add(findmessage);
            findmessage.MessageGroup.Add(findgroup);
        }
    }
}

请注意,这一职能还将产生这一信息,并确保任何集团的电文或电文都不会重复。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签