在 C# 中加入 ADO.NET Linq to Entity

发布于 2024-10-09 04:05:00 字数 372 浏览 0 评论 0原文

我尝试将系统迁移到 ADO.NET 实体,我有 3 个表

A => (Id, Name, ...)
B => (Id, Domain, ...)
c => (IdA, IdB)

VS.NET 生成 2 个实体 A 和 B,并且两者都引用了另一个表,但此引用是一个集合。我需要在表之间建立连接。

from a in A join b in B on a.? equal b.?
where condition
select new { Name = a.Name, Domain = b.Domain };

当问题增长可能成为问题时,我不能遵循实体 bu 中的参考。 有帮助吗?

I'm try to migrate a system to ADO.NET Entity I have 3 table

A => (Id, Name, ...)
B => (Id, Domain, ...)
c => (IdA, IdB)

VS.NET generate 2 entity A and B and both have reference to the other table but this reference is a collection. I need make a join between tables.

from a in A join b in B on a.? equal b.?
where condition
select new { Name = a.Name, Domain = b.Domain };

I cant do that follow the reference in entity bu when the problem grows can be a problem.
Any Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2024-10-16 04:05:01

A 和 B 之间存在多对多

VS.NET 生成 2 个实体 A 和 B,它们都引用了另一个表,但该引用是一个集合。

EF 不需要映射连接表 (C),因为它只包含外键。

使用实体上的导航属性来检索记录 - EF 将通过幕后的 JOIN 表执行静默连接。

查询以获取 A 的相关 B

var query = ctx.As.Include("Bs").Select(x => x.Bs).ToList(); // List<B>

查询以获取 B 的相关 A

var query = ctx.Bs.Include("As").Select(x => x.As).ToList(); // List<A>

这称为急切加载

另一种方法是使用延迟加载,当您稍后请求时会获取关系(我不推荐这种方法)。

您不需要在表之间执行显式联接 - 使用导航属性。

当问题变得可能成为问题时,我不能遵循实体 bu 中的参考。有什么帮助吗?

我不明白这句话 - 也许你可以澄清一下?

You have a many-to-many between A and B.

VS.NET generate 2 entity A and B and both have reference to the other table but this reference is a collection.

EF does not need to map the join table (C), because it only contains the foreign keys.

Use the navigational properties on the entites to retrieve the records - EF will do a silent join via the JOIN table behind the scenes.

Query to get related B's for A

var query = ctx.As.Include("Bs").Select(x => x.Bs).ToList(); // List<B>

Query to get related A's for B

var query = ctx.Bs.Include("As").Select(x => x.As).ToList(); // List<A>

That is referred to as eager loading.

The alternative is to use lazy loading, where the relationship is fetched when you request it later on (i don't recommend this approach).

You don't need to perform explicit joins between the tables - use the navigational properties.

I cant do that follow the reference in entity bu when the problem grows can be a problem. Any Help?

I don't understand that sentence - perhaps you can clarify?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文