如何使用EF 4.1中的Fluent API使用反射集读取自定义属性 [英] How to read Custom Attributes using reflection set by Fluent API in EF 4.1

查看:132
本文介绍了如何使用EF 4.1中的Fluent API使用反射集读取自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据注释时,我设法读取了自定义属性. 像下面的代码.

I've managed to read custom attributes when I use data annotation. like following code.

Object[] test = propertyInfo.GetCustomAttributes(typeof(KeyAttribute), true);

但是当我更改为使用Fluent API时.我再也看不到该属性了. 有什么主意吗?

But when I changed to use Fluent API. I couldn't read that attribute anymore. Any idea?

推荐答案

Fluent API未设置属性.流利的API和属性告诉EF如何构建模型.

Fluent API does not set attributes. Fluent API and Attributes tell EF how to build the model.

这是完成同一件事的两种不同方式.那就是建立模型.

These are two different ways to achieve the same thing. That is to build the Model.

修改

如果需要检索诸如主键之类的元数据,则需要访问

If you need to retrieve the metadata such as primary keys you need to access the MetadataWorkspace.

文章中包含详细信息.

这篇关于如何使用EF 4.1中的Fluent API使用反射集读取自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆