*不是*使用Entity Framework的导航属性?

时间:2022-03-14 02:16:55

Does anyone know if it's possible to not use the navigation properties feature of the entity framework for tables linked with a foreign key?

有谁知道是否有可能不使用实体框架的导航属性功能与外键链接的表?

for example, if my client table has an AddressId, I want that AddressId in my model, I don't want it to have a .Address property. But I have thus far been unable to figure out how to do this.

例如,如果我的客户端表有一个AddressId,我想在我的模型中使用AddressId,我不希望它有.Address属性。但到目前为止,我一直无法弄清楚如何做到这一点。

2 个解决方案

#1


6  

Sure, you can do this. It's just that the designer won't help you very much. Delete the navigation property, and add a scalar property for AddressId. It will work, but you'll have to be careful about hitting Update Model in the designer, as it may try to "fix" things for you. It's worth getting used to editing EDMX; it's not that bad.

当然,你可以做到这一点。只是设计师不会帮助你。删除导航属性,并为AddressId添加标量属性。它会起作用,但是你必须要小心在设计器中点击Update Model,因为它可能会试图为你“修复”一些东西。值得习惯编辑EDMX;没那么糟糕。

#2


0  

In the designer, you can set the navigation properties as having Private getters/setters. While they will still be there, because Entity Framework (by default) does lazy loading, it won't actually retrieve any data from the database at runtime. And they won't respawn the next time you update the model from the database.

在设计器中,您可以将导航属性设置为具有Private getters / setter。虽然它们仍然存在,但由于Entity Framework(默认情况下)执行延迟加载,它实际上不会在运行时从数据库中检索任何数据。并且下次从数据库更新模型时它们不会重生。

#1


6  

Sure, you can do this. It's just that the designer won't help you very much. Delete the navigation property, and add a scalar property for AddressId. It will work, but you'll have to be careful about hitting Update Model in the designer, as it may try to "fix" things for you. It's worth getting used to editing EDMX; it's not that bad.

当然,你可以做到这一点。只是设计师不会帮助你。删除导航属性,并为AddressId添加标量属性。它会起作用,但是你必须要小心在设计器中点击Update Model,因为它可能会试图为你“修复”一些东西。值得习惯编辑EDMX;没那么糟糕。

#2


0  

In the designer, you can set the navigation properties as having Private getters/setters. While they will still be there, because Entity Framework (by default) does lazy loading, it won't actually retrieve any data from the database at runtime. And they won't respawn the next time you update the model from the database.

在设计器中,您可以将导航属性设置为具有Private getters / setter。虽然它们仍然存在,但由于Entity Framework(默认情况下)执行延迟加载,它实际上不会在运行时从数据库中检索任何数据。并且下次从数据库更新模型时它们不会重生。