demndev
demndev
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
thanks!
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
what is a value converter and how can i set up it?
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
okay…
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
yes, it's something like DDD
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
it's a value object
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
i also tried using .HasColumnName, but it didn't help
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
exception:
The LINQ expression 'DbSet<UserEntity>()
.Where(u => u.Username.Value == __username_0)' 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.
The LINQ expression 'DbSet<UserEntity>()
.Where(u => u.Username.Value == __username_0)' 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.
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
what am i doing wrong?
32 replies
CC#
Created by demndev on 4/15/2023 in #help
✅ ef core can't translate a query
and the UserEntity:
public class UserEntity : EntityBase
{
public Username Username { get; }
public Password Password { get; } // TODO: work with password hashing
private List<NoteEntity> _notes = new();
public IEnumerable<NoteEntity> Notes => _notes.AsReadOnly();

public UserEntity(Password password, Username username)
{
Password = password;
Username = username;
}

public bool Authenticate(Username username, Password password)
{
return Username.Value == username.Value && Password.Value == password.Value;
}
public class UserEntity : EntityBase
{
public Username Username { get; }
public Password Password { get; } // TODO: work with password hashing
private List<NoteEntity> _notes = new();
public IEnumerable<NoteEntity> Notes => _notes.AsReadOnly();

public UserEntity(Password password, Username username)
{
Password = password;
Username = username;
}

public bool Authenticate(Username username, Password password)
{
return Username.Value == username.Value && Password.Value == password.Value;
}
32 replies
CC#
Created by demndev on 4/9/2023 in #help
✅ can't map an entity to DB
thank you!
9 replies
CC#
Created by demndev on 4/9/2023 in #help
✅ can't map an entity to DB
when I try to add a NoteEntity, I get an error:
No suitable constructor was found for entity type 'NoteEntity'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'author' in 'NoteEntity(Title title, Text text, DateTime creationDateTime, DateTime updateDateTime, UserEntity author)'
No suitable constructor was found for entity type 'NoteEntity'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'author' in 'NoteEntity(Title title, Text text, DateTime creationDateTime, DateTime updateDateTime, UserEntity author)'
9 replies
CC#
Created by demndev on 4/9/2023 in #help
✅ can't map an entity to DB
here's a NoteConfiguration:
public class NoteConfiguration : IEntityTypeConfiguration<NoteEntity>
{
public void Configure(EntityTypeBuilder<NoteEntity> builder)
{
builder.HasKey(n => n.Id);

builder.Property(n => n.Title)
.HasConversion(
title => title.Value,
value => new Title(value));

builder.Property(n => n.Text)
.HasConversion(
text => text.Value,
value => new Text(value));

builder.Property(n => n.CreationDateTime)
.HasConversion(
dt => dt.ToString(CultureInfo.InvariantCulture),
value => DateTime.Parse(value));

builder.Property(n => n.UpdateDateTime)
.HasConversion(
dt => dt.ToString(CultureInfo.InvariantCulture),
value => DateTime.Parse(value));

builder
.HasOne<UserEntity>("Author")
.WithMany()
.HasForeignKey(n => n.AuthorId)
.IsRequired();
}
}
public class NoteConfiguration : IEntityTypeConfiguration<NoteEntity>
{
public void Configure(EntityTypeBuilder<NoteEntity> builder)
{
builder.HasKey(n => n.Id);

builder.Property(n => n.Title)
.HasConversion(
title => title.Value,
value => new Title(value));

builder.Property(n => n.Text)
.HasConversion(
text => text.Value,
value => new Text(value));

builder.Property(n => n.CreationDateTime)
.HasConversion(
dt => dt.ToString(CultureInfo.InvariantCulture),
value => DateTime.Parse(value));

builder.Property(n => n.UpdateDateTime)
.HasConversion(
dt => dt.ToString(CultureInfo.InvariantCulture),
value => DateTime.Parse(value));

builder
.HasOne<UserEntity>("Author")
.WithMany()
.HasForeignKey(n => n.AuthorId)
.IsRequired();
}
}
and a UserConfiguration:
public class UserConfiguration : IEntityTypeConfiguration<UserEntity>
{
public void Configure(EntityTypeBuilder<UserEntity> builder)
{
builder.HasKey(u => u.Id);

builder.Property(u => u.Username)
.HasConversion(
u => u.Value,
value => new Username(value));

builder.Property(u => u.Password)
.HasConversion(
p => p.Value,
value => new Password(value));

// builder // i tried with and without it; but it still doesn't work
// .HasMany(u => u.Notes)
// .WithOne(n => n.Author)
// .HasForeignKey("AuthorId")
// .IsRequired();
}
}
public class UserConfiguration : IEntityTypeConfiguration<UserEntity>
{
public void Configure(EntityTypeBuilder<UserEntity> builder)
{
builder.HasKey(u => u.Id);

builder.Property(u => u.Username)
.HasConversion(
u => u.Value,
value => new Username(value));

builder.Property(u => u.Password)
.HasConversion(
p => p.Value,
value => new Password(value));

// builder // i tried with and without it; but it still doesn't work
// .HasMany(u => u.Notes)
// .WithOne(n => n.Author)
// .HasForeignKey("AuthorId")
// .IsRequired();
}
}
9 replies
CC#
Created by demndev on 4/9/2023 in #help
✅ can't map an entity to DB
and a UserEntity:
public class UserEntity
{
public int Id { get; set; }
public Username Username { get; }
public Password Password { get; } // TODO: work with password hashing
private readonly List<NoteEntity> _notes = new();
public IEnumerable<NoteEntity> Notes => _notes.AsReadOnly();

public UserEntity(string password, string username)
{
Password = new Password(password);
Username = new Username(username);
}
}
public class UserEntity
{
public int Id { get; set; }
public Username Username { get; }
public Password Password { get; } // TODO: work with password hashing
private readonly List<NoteEntity> _notes = new();
public IEnumerable<NoteEntity> Notes => _notes.AsReadOnly();

public UserEntity(string password, string username)
{
Password = new Password(password);
Username = new Username(username);
}
}
9 replies
CC#
Created by demndev on 4/9/2023 in #help
✅ can't map an entity to DB
I have a NoteEntity:
public class NoteEntity
{
public int Id { get; set; }
public Title Title { get; }
public Text Text { get; }
public DateTime CreationDateTime { get; }
public DateTime UpdateDateTime { get; }

public UserEntity Author { get; private set; }
public int AuthorId { get; private set; }

public NoteEntity(Title title, Text text, DateTime creationDateTime, DateTime updateDateTime, UserEntity author)
{
Title = title;
Text = text;
CreationDateTime = creationDateTime;
UpdateDateTime = updateDateTime;
AuthorId = author;
}
}
public class NoteEntity
{
public int Id { get; set; }
public Title Title { get; }
public Text Text { get; }
public DateTime CreationDateTime { get; }
public DateTime UpdateDateTime { get; }

public UserEntity Author { get; private set; }
public int AuthorId { get; private set; }

public NoteEntity(Title title, Text text, DateTime creationDateTime, DateTime updateDateTime, UserEntity author)
{
Title = title;
Text = text;
CreationDateTime = creationDateTime;
UpdateDateTime = updateDateTime;
AuthorId = author;
}
}
9 replies
CC#
Created by demndev on 4/7/2023 in #help
The best place to handle domain exceptions in an MVC app?
for what kind of context result objects will be better than exceptions?
17 replies
CC#
Created by demndev on 4/7/2023 in #help
The best place to handle domain exceptions in an MVC app?
good. probably I will use this approach
17 replies
CC#
Created by demndev on 4/7/2023 in #help
The best place to handle domain exceptions in an MVC app?
yes…
17 replies
CC#
Created by demndev on 4/7/2023 in #help
The best place to handle domain exceptions in an MVC app?
what about to make an exception filter for each controller action?
17 replies
CC#
Created by demndev on 4/7/2023 in #help
The best place to handle domain exceptions in an MVC app?
and do all checks about all type of exceptions?
17 replies
CC#
Created by demndev on 4/7/2023 in #help
The best place to handle domain exceptions in an MVC app?
what to use instead? result objects?
17 replies