在 DataEntity 上绑定标量属性(DataEntity Framework)
伙计们,我是 C# DataEntity Framework 的新手。 我在数据库中有 2 个表: 具有字段 id、measurementId 的车辆。 使用 ID、名称字段进行测量。 他们一对一地联系在一起。一辆车有一种措施。
我想扩展要存储MeasurementName 字段的实体Vehicles。我已经创建了属性MeasurementName,但如何将其绑定到Measurement.Name。在DataEntity框架中可以吗?
我知道我可以通过另一种方式实现它,例如使用 Entity Linq,我将在其中创建新的
class Test
{
Id= id,
Measurement = measurement.Name
};
但是是否可以扩展 DataEntity 以具有此属性?
folks, i am new to C# DataEntity Framework.
I have 2 tables in DB :
Vehicle with fields id, measurementId.
Measurement with fields Id, Name.
They related as one to one. One vehicle have one measure.
I want to expand entity Vehicles where i want to store MeasurementName field. I've created property MeasurementName, but how i can bind it to Measurement.Name. Is it possible in DataEntity framework ?
I know that i can achive it another way, for example using Entity Linq where i will create new
class Test
{
Id= id,
Measurement = measurement.Name
};
But is it possible to expand DataEntity to have this property ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型中的每个实体均作为 实现部分类,意味着定义该类的全部代码可以存在于多个文件中,但会被编译为一个对象。这使得它们具有高度可扩展性,因为您可以将属性和函数添加到实体框架设计器生成的代码中。在同一命名空间中创建一个与您的实体同名的新分部类,并添加自定义属性,如下所示
如果此答案对您有帮助,请务必投票或将其标记为已接受的答案。
Each of the entities in your model is implemented as a partial class, meaning the total code that defines the class can exist in multiple files but gets compiled into one object. This makes them highly extensible as you can add properties and functions to the code generated by the Entity Framework designer. Create a new partial class with the same name as your entity in the same namespace and add the custom property like so
If this answer was helpful to you, please be certain to vote it up or mark it as the accepted answer.