cypherpotato
cypherpotato
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
also i'll follow the tip of naming of anonymous objects
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
but yea, thank you guys
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
what no
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
No description
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
but I've always seen anonymous members closer to fields than properties
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
the JSON is configured to sent everything as camelCase btw
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
hahaa you're right
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
what
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
nope. my foreign keys are set in OnModelCreating. I don't use navigation in models
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
this was the final query
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
C#
var query = Database.KanbanColumns
.Where(c => c.ParentBoardId == boardId)
.OrderBy(c => c.Order)
.Select(c => new
{
Column = c,
Cards = Database.KanbanCards
.Where(a => a.ParentColumnId == c.Id)
.OrderBy(a => a.Order)
.ToArray()
});

foreach (var data in query)
{
yield return new
{
column = new
{
data.Column.Id,
data.Column.Color,
data.Column.Label
},
cards = data.Cards
.Select(a => new
{
a.Id,
Title = a.CardTitle,
Info = new
{
a.CreatedAt,
a.Value,
a.Temperature,
AssociatedUsers = a.AssociatedUsers
.Select(n => AdapterCacheUnit.FetchUser(n))
.Where(n => n != null)
.Select(n => new
{
n!.UniqueId,
n.UserName,
n.ProfilePictureUrl
})
}
})
};
}
C#
var query = Database.KanbanColumns
.Where(c => c.ParentBoardId == boardId)
.OrderBy(c => c.Order)
.Select(c => new
{
Column = c,
Cards = Database.KanbanCards
.Where(a => a.ParentColumnId == c.Id)
.OrderBy(a => a.Order)
.ToArray()
});

foreach (var data in query)
{
yield return new
{
column = new
{
data.Column.Id,
data.Column.Color,
data.Column.Label
},
cards = data.Cards
.Select(a => new
{
a.Id,
Title = a.CardTitle,
Info = new
{
a.CreatedAt,
a.Value,
a.Temperature,
AssociatedUsers = a.AssociatedUsers
.Select(n => AdapterCacheUnit.FetchUser(n))
.Where(n => n != null)
.Select(n => new
{
n!.UniqueId,
n.UserName,
n.ProfilePictureUrl
})
}
})
};
}
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
yea by the end i've rewrited the entire query to use IEnumerable instead
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
I thought I could use AsEnumerable in nested queries. If I use it at the root, will the nested queries also be executed on the client side?
33 replies
CC#
Created by cypherpotato on 11/19/2024 in #help
✅ Why ins't this EF Core query being evaluated client-side?
Btw i'm getting the following exception, telling my expression ins't being evaluated on client side.
System.InvalidOperationException: The LINQ expression 'n => AdapterCacheUnit.FetchUser(n)' could not be translated.
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call
to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038
for more information.
System.InvalidOperationException: The LINQ expression 'n => AdapterCacheUnit.FetchUser(n)' could not be translated.
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call
to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038
for more information.
what am I doing wrong?
33 replies
CC#
Created by cypherpotato on 10/8/2024 in #help
Generic converter bounding in EF Core
so, what's the better way to create an converter for all EntityId<> without using reflection and activator?
3 replies
CC#
Created by cypherpotato on 10/8/2024 in #help
Generic converter bounding in EF Core
currently, i'm using this:
static void ApplyGenericConverter(ModelBuilder modelBuilder, Type commonType, Type converterGenericType, int? maxLength = null)
{
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
var properties = entityType.ClrType.GetProperties()
.Where(p => p.PropertyType.IsAssignableTo(commonType));

foreach (var property in properties)
{
var converterType = converterGenericType.MakeGenericType(property.PropertyType.GenericTypeArguments[0]);

var converter = Activator.CreateInstance(converterType);
if (converter is null)
{
throw new Exception("Error creating the dynamic converter object: " + entityType.ClrType.ToString() + " Property: " + property.ToString());
}

var builder = modelBuilder.Entity(entityType.Name).Property(property.Name)
.HasConversion((ValueConverter)converter);

if (maxLength is int ml) builder = builder.HasMaxLength(ml);
}
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
ApplyGenericConverter(modelBuilder, typeof(IEntityId), typeof(EntityIdValueConverter<>), maxLength: 26 + 1 + 3);
ApplyGenericConverter(modelBuilder, typeof(IJsonBox), typeof(JsonBoxValueConverter<>));
}
static void ApplyGenericConverter(ModelBuilder modelBuilder, Type commonType, Type converterGenericType, int? maxLength = null)
{
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
var properties = entityType.ClrType.GetProperties()
.Where(p => p.PropertyType.IsAssignableTo(commonType));

foreach (var property in properties)
{
var converterType = converterGenericType.MakeGenericType(property.PropertyType.GenericTypeArguments[0]);

var converter = Activator.CreateInstance(converterType);
if (converter is null)
{
throw new Exception("Error creating the dynamic converter object: " + entityType.ClrType.ToString() + " Property: " + property.ToString());
}

var builder = modelBuilder.Entity(entityType.Name).Property(property.Name)
.HasConversion((ValueConverter)converter);

if (maxLength is int ml) builder = builder.HasMaxLength(ml);
}
}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
ApplyGenericConverter(modelBuilder, typeof(IEntityId), typeof(EntityIdValueConverter<>), maxLength: 26 + 1 + 3);
ApplyGenericConverter(modelBuilder, typeof(IJsonBox), typeof(JsonBoxValueConverter<>));
}
but that doens't seems correct. each entity has an strong typed ID EntityId<TEntity>, and I want to map all of them for all entities.
3 replies
CC#
Created by cypherpotato on 8/27/2024 in #help
How to sustain TcpListener keep-alive?
i figured out the next http requests was returning to the same network stream
4 replies
CC#
Created by cypherpotato on 8/27/2024 in #help
How to sustain TcpListener keep-alive?
i just had to put the http session in an while loop
4 replies
CC#
Created by cypherpotato on 6/4/2024 in #help
can I specify an Type wildcard for GetMethod?
this snippet:
void Foo(string foo, string? n, object? b) { }
void Foo(string foo, string? n, string? b) { }

public void DoFoo()
{
Foo("aaa", null, null);
}
void Foo(string foo, string? n, object? b) { }
void Foo(string foo, string? n, string? b) { }

public void DoFoo()
{
Foo("aaa", null, null);
}
the compiler automatically select Foo(string, string?, string?) as the method for Foo, even if I've not specified any argument but null. How did the compiler made this decision?
7 replies
CC#
Created by cypherpotato on 5/29/2024 in #help
✅ Disable trimming for certain assemblies
but will it work for AOT compilation?
6 replies