-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EntityFrameworkExperimentalAttribute #26229
Comments
|
Thanks @jeffhandley. I'll look into this tomorrow. We may be able to use it in 6.0 for #26232. |
@jeffhandley I can't seem to make RequiresPreviewFeaturesAttribute work. I don't get any warnings or errors when using it. What am I missing here? I'm using a local build of EF Core. My code checks that the attribute is present: using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.Extensions.Logging;
public class Foo
{
public int Id { get; set; }
public string? Bar { get; set; }
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseInMemoryDatabase("Test")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<Foo>()
.Property(e => e.Bar)
.HasConversion(new MyConverter());
}
}
public class Program
{
public static void Main()
{
var attributes = typeof(ValueConverter<,>)
.GetConstructors()
.Single(c => c.GetParameters().Any(p => p.Name == "convertsNulls"))
.GetCustomAttributes(true)
.ToList();
foreach (var attribute in attributes)
{
Console.WriteLine($"Found: {attribute.GetType().Name}");
}
using (var context = new SomeDbContext())
{
context.Add(new Foo { Bar = "X" });
context.SaveChanges();
}
using (var context = new SomeDbContext())
{
Console.WriteLine(context.Set<Foo>().Single().Bar);
}
}
}
public class MyConverter : ValueConverter<string?, string?>
{
public MyConverter()
: base(v => v, v => v, convertsNulls: true)
{
}
} csproj: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.0-dev" />
</ItemGroup>
</Project> Build correctly warns for using EF internal code, but nothing for the preview attribute:
Running also results in no errors:
|
I'm unsure from those details if you have 6.0 RC2+ SDK in place. The Thanks! |
SDK is 6.0.100-rc.2.21505.57 |
@jeffhandley I tried creating a minimal class library and a console app referencing it (no EF), and I still can't get it to work. See attached. |
I wonder if this is related to using |
@roji I tried it with a direct assembly reference, rather than a project reference, and there was no difference. Didn't try building it into a package. |
Could be worth a try, we know that analyzers and assembly/project/package references are tricky.. |
Thanks for this. I meant to leave a comment earlier--I'm investigating this. It's not behaving as I expected it to, and I've repro'd this behavior with an even simpler scenario. I'll follow back up later. |
Thanks @jeffhandley |
@ajcvickers Thanks a bunch for trying this out and letting me know it wasn't working as expected. This uncovered that we had a 6.0 GA ship-blocker issue lurking here that had gone undetected. That fix is now in place and it will make the GA snap. To work around the bug until you take in an SDK build with the fix though, you can select the CA2252 analyzer from your dependencies and set it to Error severity in your project's editorconfig. |
Should this be closed with the addition of [Experimental] Attribute in .Net 8? |
@KennethHoff yeah, probably - removing from the backlog to re-triage. |
Introduce an EntityFrameworkExperimentalAttribute, which works like the EntityFrameworkInternalAttribute, except that it indicates a feature is experimental for the current release, rather than internal.
The text was updated successfully, but these errors were encountered: