Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:40:52+00:00 2026-05-26T01:40:52+00:00

My code is as below. public void CreateNewAuthor(List<Author> newAuthor) { publishContext.AddToAuthors(newAuthor); } I know

  • 0

My code is as below.

public void CreateNewAuthor(List<Author> newAuthor)
{
    publishContext.AddToAuthors(newAuthor);
}

I know this will result in error as AddToAuthors(Author newAuthor) accepts entity object as parameter while I am passing a List<>. So how this should be handled? How to cast a List<> to entity object before AddToAuthors()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:40:53+00:00Added an answer on May 26, 2026 at 1:40 am

    You’re accepting multiple authors – but you’re trying to call something which takes a single author. Are you expecting multiple values within your list, or just a single one?

    It sounds like you might just want to loop:

    public void CreateNewAuthor(List<Author> newAuthors)
    {
        foreach (Author newAuthor in newAuthors)
        {
            publishContext.AddToAuthors(newAuthor);
        }
    }
    

    … or it’s entirely possible that the context already provides a way of adding multiple authors at a time. (I’m not an EF person, so I don’t know for sure.)

    The important thing is that you understand the possibilities here – the list could contain no authors, one author or multiple authors. Are all of those valid in your code? How do you want to handle each of those situations?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this error message with the code below: class Money { public: Money(float
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
The code looks like below: namespace Test { public interface IMyClass { List<IMyClass> GetList();
I have this piece of code from GWT in Action: public void processOperator(final AbstractOperator
My code as below public void DownloadConcurrent(Action<string> Methord) { Action<string>[] methordList = new Action<string>[Concurent_Downloads];
I have the following code: public void DeleteAccountsForMonth(int year, int month) { var result
See code just bellow Our generic interface public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> { void add(INSTANCE_CLASS
I have the code below : public class Anything { public int Data {
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
The below code in Java throws Null pointer exception. public class New{ int i;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.