add some field to output of a method and save it into a table

fahime abouhamze 21 Reputation points
2021-07-24T13:18:25.943+00:00

I have this method and it's output

          var lista = allPerson.Select(c => new { c.Id, c.Smstext , c.Mobile}).ToList();

I want to insert into a table with bellow properties :

 TblMessageBranch tblMessage  = new TblMessageBranch()
        {
            PID = ,
            MessageText = ,
            SendingTime = DateTime.Now,
            Address = ,
            ProviderId = 49,
            IsTransferred = false,
            MessageDate = ,
            MessageType = smsTypeSelect


        };

I do not know how to use the output of above method into this table ?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,925 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 117.3K Reputation points
    2021-07-24T14:01:11.45+00:00

    You can do something like this:

    List<TblMessageBranch> messages = 
       lista.Select( p =>
          new TblMessageBranch
             {
                 PID = p.Id,
                 MessageText = p.Smstext,
                 SendingTime = DateTime.Now,
                 Address = ???, // maybe 'p.Mobile'?
                 ProviderId = 49,
                 IsTransferred = false,
                 MessageDate = ???, // maybe 'DateTime.Now'?
                 MessageType = smsTypeSelect
             } ).ToList( );
    

    It is not clear how to get some of the fields.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.