通过EF6和LINQ从Oracle DB接收相关实体

时间:2019-02-15 08:48:20

标签: asp.net-mvc oracle entity-framework linq

我正在开发一个Web应用程序,该应用程序可以显示Oracle数据库中的数据。

例如,如果我需要显示零件,则需要以下关系:

Parts have 0-1 AdditionalInformations
Parts have 0-1 ReferencePart
Parts have 1   Type 
Parts have 1-* Tasks
Parts have 0-* Locations

此外:

AdditionalInformations have 0-* Users
And Locations          have 1   AdditionalLocationInfo

所以我想从db获取一个Part,配置上下文,然后再显示包括前面提到的关系的Part。

我将EntityFramework 6和LINQ一起用于查询。还有一个ORACLE 12c数据库来保存数据

var query = from part in _dbcontext.Part.AsNoTracking()
            where part.Id == partId
            select part;
return query
        .Include(p => p.Type)
        .Include(p => p.AdditionalInformations.Users)
        .Include(p => p.ReferencePart)
        .Include(p => p.Locations.Select(l => l.AdditionalLocationInfo))
        .Include(p => p.Tasks)
        .SingleOrDefault();

可悲的是,这给了我ORA-01790例外...
如果我使用更少的包含,它将起作用! :

var query = from part in _dbcontext.Part.AsNoTracking()
            where part.Id == partId
            select part;
return query
        .Include(p => p.Type)
        .Include(p => p.Locations.Select(l => l.AdditionalLocationInfo))
        .SingleOrDefault();


var query = from part in _dbcontext.Part.AsNoTracking()
            where part.Id == partId
            select part;
return query
        .Include(p => p.Type)
        .Include(p => p.AdditionalInformations.Users)
        .Include(p => p.ReferencePart)
        .SingleOrDefault();

但是,我需要所有关系...

所以请给我有关如何解决此问题的意见:)谢谢!

0 个答案:

没有答案