Detached-Mapper: Unable to find package

Hi, I decided to give Detached a try, but when trying to install it in my current project I get

PM> Install-Package Detached.Mappers.EntityFramework
Install-Package : Unable to find package 'Detached.Mappers.EntityFramework'
At line:1 char:1
+ Install-Package Detached.Mappers.EntityFramework
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
 
Time Elapsed: 00:00:03.7855917

It seems it’s not present on the Nuget package Manager. Any workaround?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

Hi again @pinoli Good, I’m glad you were able to sort out all of the library issues.

If you look at this class: https://github.com/leonardoporro/Detached-Mapper/blob/main/src/Detached.Mappers.EntityFramework/Context/EntityFrameworkMapperContext.cs

There is a OnMapperAction method, it receives the entity, the DTO, the key and a MapperActionType: Load/Create/Update/Delete. For Load, a full query is run, in this state, all the entities should be in the ChangeTracker. For the mutation actions, detached tries to get the entity from the change tracker or create a new one, and set the EntityState. That is what you would normally do manually. I think that you could customize this class to suite your needs, but I need to re-read your sample to tell you exactly what (will do later). Once you have your customized mapper context, it can be passed to the mapper class without modifying the library. Take a look at https://github.com/leonardoporro/Detached-Mapper/blob/main/src/Detached.Mappers.EntityFramework/Extensions/DbContextExtensions.cs, line 30 to see how.

Anyway Detached does a kind of upsert, need to read your sample later to see why doesn’t work, my brain is burnt out now.

hey @leonardoporro thank you very much, the problem disappeared after updating to 3.1.10 I also noticed I could not use enums (and I was doing it in three different objects), otherwise I would get the same error I got for bool but with the enum type instead.

I am making progress 😊 Unfortunately, I am getting stuck while inserting keyless objects, as I’ve shown before.

System.Private.CoreLib: Exception while executing function: TestDetached. Detached.Mappers: Indexer [System.Int32] doesn't exist in System.Collections.Generic.ICollection`1[TD.Models.RowModifier].

Basically this code is giving me this error, and I don’t know why. When I remove it, it doesn’t throw this error, but EF complains (rightly) there is no key to establish a relationship with the parent object, where a navigation property to the keyless child is set.

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

public Object()
{
    Id = Guid.NewGuid()
}

it looks like Detached doesn’t allow to do this. If you know a workaround please let me know.

I think that Id is working ok, check my previous comment. Would be possible to change the property type to List<> ?

ImportJsonAsync: json should start with [ as it is expecting an array.

Hey @pinoli, I just reviewed the code and it was totally my fault! I forget to put Boolean in the list of primitives, so that mapper was considering it an object. There are two solutions:

  • Update to 3.1.10 Or
  • Add boolean as primitive manually: optionsBuilder.UseDetached(o => o.Primitives.Add(typeof(bool)));

Sorry for the poor support, it is just only me here. But if we could convince more people to join in…

Here it is the code I used to reproduce the bug: ` class Program { static void Main(string[] args) { Db db = new Db(); db.Database.EnsureCreated();

        var s = db.Map<Entity>(new Entity
        {
            Id = 10,
            Value = true
        });

        db.SaveChanges();


        var e = db.Entities.ToList();
    }
}

public class Db : DbContext
{
    static SqliteConnection cnn = new SqliteConnection(@$"Data Source=c:\mydb.db");

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        cnn.Open();
        optionsBuilder.UseDetached(o => o.Primitives.Add(typeof(bool)));
        optionsBuilder.UseSqlite(cnn);
    }

    public DbSet<Entity> Entities { get; set; }
}

[Entity]
public class Entity
{
    [Key]
    public int Id { get; set; }

    public bool Value { get; set; }
}

`

El jue., 22 oct. 2020 15:56, pinoli notifications@github.com escribió:

Did you add a [Composition] attribute over a bool property? “Can’t construct bool” looks like it is handing a bool like a complex type.

this is the first thing I check, unfortunately no bool properties are marked as [Composition] or [Aggregation]. I carefully review each object in the model, set [Entity] in every object and also added new MapperParameters { EnsureAggregations = true } to my MapAsync call.

As I told you, I have some nested object with no key, and as a workaround I generate the Guid when creating a new istance. object constructor

    public Object()
    {
        Id = Guid.NewGuid();
    }

object id settings

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public Guid Id { get; set; }

I am unfortunately still getting the same message

Detached.Mappers: Can’t construct bool. It does not have a parameterless constructor or a concrete type specified.

Should I open a new issue? Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/leonardoporro/Detached-Mapper/issues/19#issuecomment-714694939, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE6UPEREHWLYWITKRPZ4SDSMB57VANCNFSM4SXAVL6Q .

Hi @pinoli, thank you for giving a try I installed it using Install-Package Detached.Mappers.EntityFramework -Version 5.0.0-rc.2.20475.6 and worked well. Do you have VS 2019 and net 5 installed? This package is built using EF Core 5 preview (since it seems to be the first decent version of EF Core). I saw over here (https://github.com/dotnet/efcore/issues/23044) that you have the same problem as me and many other people. I’ll be glad to help if you provide a bit more of context.