[英]I want to fetch multiple data from oracle database and want to store it into another variables in C# .net
[英].NET C# I want to get the IDs (1/multiple) from a data if it much the ID of another table
楷模:
namespace practise_API.Model
{
public class SourceAttributes
{
[Key]
public int SourceEntityId { get; set; }
public int ATiD { get; set; }
public string Name { get; set; }
public string Datatype { get; set; }
}
public class OtherData
{
public int ID { get; set; }
public string Ename { get; set; }
public string Type { get; set; }
public string Source { get; set; }
public string Frequency { get; set; }
}
}
IRepository
接口:
namespace API.Repository
{
public interface ISourceRepository
{
IEnumerable<SourceEntities> GetSourceEntities();
IEnumerable<SourceAttributes> GetSourceAttributes(int id);
........
void Save();
}
}
Repository
实现:
public class SourceRepository : ISourceRepository
{
private readonly MapperDbContext _dbContext;
public SourceRepository(MapperDbContext dbContext)
{
_dbContext = dbContext;
}
public IEnumerable<SourceAttributes> GetSourceAttributes()
{
return _dbContext.SourceAttributes
.Where(i => i.SourceEntityId == OtherData.ID)
.ToList();
}
}
我想从OtherData
SourceAttributes.SourceentityIds
我想到的方法是使用 where() System.Linq 但我无法获得 OtherData.ID。
这也将在我的 controller 的Get()
中调用。
ISourceRepository.GetSourceAttributes
有一个id
参数,但实现缺少它肯定会导致编译器错误。 修改它:
public IEnumerable<SourceAttributes> GetSourceAttributes(int otherDataId)
{
return _dbContext.SourceAttributes
.Where(i => i.SourceEntityId == otherDataId)
.ToList();
}
要获取您想要的 ID:
var ids = sourceRepository
.GetSourceAttributes(myOtherDataInstance.ID)
.Select(i => i.ID)
.ToArray(); // or leave it as IEnumerable as you wish
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.