Warn when no service to replace
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
Research direction
Start with the ReplaceService<SqlServerTypeMapper, CustomSqlServerTypeMapper>() call and reproduce the behavior using the supplied ReplaceTypeMapperOk test on EF Core 2.0. Trace the service-replacement path to determine why the custom mapper is not invoked; done means the issue is diagnosed and the requested warning is covered by a regression test.
Written by the indexing model from the issue text.
Description
I'm trying to create an example of replacing a service inside EF Core as shown in a Channel 9 video by Rowan Miller starting at 45 minutes in.
My example (see below) doesn't work. And I can confirm that the constructor is not called, nor the overriden method are called, as my break points are never triggered. Can you tell me what I am doing wrong.
Steps to reproduce
Here is one of the versions I have tried (I have tried a few permutations and none work).
Here is the unit test, with the new CustomSqlServerTypeMapper
public class CustomSqlServerTypeMapper : SqlServerTypeMapper
{
public CustomSqlServerTypeMapper(RelationalTypeMapperDependencies dependencies)
: base(dependencies) {}
public override RelationalTypeMapping FindMapping(IProperty property)
{
var currentMapping = base.FindMapping(property);
if (property.ClrType == typeof(string) && property.Name.EndsWith("Ascii"))
return new StringTypeMapping(currentMapping.StoreType,
currentMapping.DbType, true, currentMapping.Size);
return currentMapping;
}
public override RelationalTypeMapping FindMapping(string storeType)
{
return base.FindMapping(storeType);
}
}
[Fact]
public void ReplaceTypeMapperOk()
{
//SETUP
var connectionString = AppConstants.ConnectionString;
var optionsBuilder = new DbContextOptionsBuilder<TestDbContext>();
optionsBuilder.UseSqlServer(connectionString);
optionsBuilder.ReplaceService<SqlServerTypeMapper, CustomSqlServerTypeMapper>();
using (var context = new TestDbContext(optionsBuilder.Options))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
//ATTEMPT
var entity = context.Model.FindEntityType(typeof(ScalarEntity));
var mapInfo1 = entity.GetProperty(nameof(ScalarEntity.StringAscii));
//VERIFY
mapInfo1.ClrType.ShouldEqual(typeof(string));
mapInfo1.IsUnicode().ShouldEqual(false);
}
}
My entity class is
public class ScalarEntity
{
public int Id { get; set; }
public string StringMax { get; set; }
[Required]
[MaxLength(20)]
public string String20 { get; set; }
public string StringAscii { get; set; }
}
Further technical details
EF Core version: 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: VS2017 15.3
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100