I am putting together a new web application template for myself using .AspNetCore 2.0 and EFCore 2.0.
In my test project I am doing some testing with both creating the context and adding to DbSets.
Here is the context creation method.
public static ApplicationDbContext CreateDbContext(string[] args)
{
var basepath = GetBasePath("Application.UI");
var configuration = new ConfigurationBuilder()
.SetBasePath(basepath)
.AddJsonFile("appsettings.json")
.Build();
//Set up configuration sources.
var connectionString = configuration.GetConnectionString("DefaultConnection");
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer(connectionString);
return new ApplicationDbContext(builder.Options);
}
Here is the test method where the error message is.
[TestMethod]
public void AddContact_WithDates_ShouldGetAdded()
{
//Arrange
var ct = new ContactUs
{
ContactWho = ContactWho.Support,
Message = "Please call me about website problems",
Email = "[email protected]",
MessageSentTimestamp = DateTime.UtcNow,
FirstName = "Jim",
LastName = "Simons",
ReportingError = false,
MobilePhone = "5555556666"
};
var appArgs = new[] {"TestApp"};
var context = ApplicationDbContextFactory.CreateDbContext(appArgs);
//Act
context.ContactUss.Add(ct);
//Assert
Assert.IsNotNull(context);
}
The context is created correctly. ContactUs (ContactUss is the DbSet of ContactUs) is just a standard domain class.
But VS2017 is giving me a red squiggly under ct in the Add(ct) call with the error message
Argument type ContactUs is not assignable to parameter of type TEntity
This has always been how I've worked with EF. Is there something new in Core that I'm missing?

Addwill in fact add the entity because EF Core is very well tested. It already has tests to ensure that functionality works correctly; creating your own is useless.