gpt4 book ai didi

c# - 使用泛型的脑残错误

转载 作者:行者123 更新时间:2023-11-30 19:43:16 24 4
gpt4 key购买 nike

<分区>

我正在尝试创建通用 Repository pattern 基类,从中实现成员。这是一个代码:

public abstract class RepositoryBase<TEntity, TType> : IRepository<TEntity, TType>
where TEntity : EntityBase<TType>
{
public IAdNetMsSqlContext Context { get; set; }
public DbSet<TEntity> DbSet { get; set; }

public RepositoryBase(IAdNetMsSqlContext context)
{
Context = context;
DbSet = context.Set<TEntity>();
}

public IQueryable<TEntity> Get(TType id)
{
//!!! Here is an error
return DbSet.FirstOrDefault(e => e.Id == id);
}
....
}

我得到了错误:

   Error    1   Operator '==' cannot be applied to operands of type 'TType' and    `'TType' .... AdNet.Common.Base

行内:

   return DbSet.FirstOrDefault(e => e.Id == id);

我不知道该怎么想。 TType 肯定等于 TType。

感谢任何预付款!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com