Title: Stored Procedure with less parameters than associated object
Tags: c#;entity-framework;stored-procedures;entity-framework-6
Question: I have a stored procedure (```sp_create_user```) in my database that creates a user in my ```Users``` table. This is my stored procedure definition:

```ALTER PROCEDURE sp_create_user
    @Username nvarchar(50),
    @Password nvarchar(50),
AS
BEGIN
    -- SQL STATMENTS
END
```

My ```User``` object in c# is this:

```public partial class User
{
    public User()
    {
    }

    public int UserId { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
```

And this is my EF mapping the User entity insert to that stored procedure:

```modelBuilder.Entity<User&gt;().MapToStoredProcedures(
  s =&gt;
      s.Insert(i =&gt; i.HasName("sp_create_user"))
);
```

When I try to execute a new creation of user I get an exception that the number of parameters sent to the stored procedure is too big. After tracing the query, I see that it sends to the stored procedure all the fields that the ```User``` class has.

How can I tell EF to send only the relevant fields for the stored procedure?

Comment: That's what I ended up doing :(

Comment: Side note if this is for **SQL Server**: you should **not** use the `sp_` prefix for your stored procedures. Microsoft has [reserved that prefix for its own use (see *Naming Stored Procedures*)](http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx), and you do run the risk of a name clash sometime in the future. [It's also bad for your stored procedure performance](http://www.sqlperformance.com/2012/10/t-sql-queries/sp_prefix). It's best to just simply avoid `sp_` and use something else as a prefix - or no prefix at all!

Comment: Can't you just add the parameters to the SP? :)


Here is another answer: ```...
[System.ComponentModel.DataAnnotations.Schema.NotMapped]
public int UserId { get; set; }

public string Username { get; set; }
public string Password { get; set; }

[System.ComponentModel.DataAnnotations.Schema.NotMapped]
public string FirstName { get; set; }

[System.ComponentModel.DataAnnotations.Schema.NotMapped]
public string LastName { get; set; }
...
```

You can also try the following if you don't want to modify the class:

```modelBuilder.Entity<User&gt;().Ignore(u =&gt; u.UserId);
```

Comment for this answer: is there a way to define it in the mapping without interfering with  the entity class?
Comment for this answer: What will "Ignore" do? will it have effects later on on regular EF update? because on update I would like to send some of the fields I don't send on SP insert

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:11/20/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><entity-framework><stored-procedures><entity-framework-6>', 'Title': 'Stored Procedure with less parameters than associated object', 'ViewCount': 222, 'id': 27048809, 'user_AboutMe': "<p>Loves challenges... I love learning new things, and I love technology (sometimes too obsessive about it that it's hard to decide which is better - that's why I'm here, to ask and learn and teach what I know).</p>\n", 'user_AccountId': 3135658.0, 'user_DisplayName': 'developer82', 'user_Reputation': 12740.0, 'user_Views': 929.0, 'user_id': 2652208.0}}