ASP.NET SQL 配置文件提供程序 - ProfileBase.Create() 方法是否访问数据库?
我正在使用 SQLMemebershipProvider 并使用配置文件。 我有一个名为 UserProfile 的自定义类,它继承自 ProfileBase 类,我使用它来设置“FullName”等自定义属性。 我想循环访问数据库中的所有用户并访问他们的配置文件属性。 在每次迭代中,我都会调用 ProfileBase.Create() 来获取新的配置文件,然后访问属性。
在我看来,每次调用 ProfileBase.Create() 时,它都会访问我的 SQL 数据库。 但我只是在寻找对此的确认。 那么,有谁知道这是否每次都会击中数据库?
更好的是,是否有人有更好的解决方案来帮助我一次调用数据库来获取所有用户的自定义配置文件属性?
我知道我可以编写自己的存储过程,但我想知道是否有一种内置于会员资格提供程序中的方法。
I am working with the SQLMemebershipProvider and using Profiles. I have a custom class called UserProfile that inherits from the ProfileBase class and I use this to set custom properties like "FullName". I am wanting to loop through all the users in the database and get access to their profile properties. On each iteration I am calling ProfileBase.Create() to get a new profile and then access the properties.
It looks to me like every time ProfileBase.Create() is called it hits my SQL database. But I am just looking for confirmation of this. So, does anyone know if this does in fact hit the DB each time?
And better yet, does anyone have a better solution of how I could make one call to the DB to get all users with their custom profile attributes?
I know I could write my own stored proc, but I am wondering if there is a way built in to the Membership Provider.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
迈克,我相信你所观察到的是真的。 我正在使用使用 Azure TableStorage 作为数据存储的 ProfileProvider。 我想从数据库中获取用户配置文件列表,并将它们与会员提供商的信息合并。
我花了一些时间才意识到,使用用户名作为参数调用 ProfileBase.Create() 会执行对 TableStorage 的查找,并实际上检索与该用户名关联的数据。 就我而言,调用此方法 Create() 会产生误导,我希望使用 Load() 或 Get()。
目前我的代码如下所示:
是否有更好(更直接、更高效)的方法来
我看过 Web Profile Builder 但在我看来,这仅为自定义提供设计时智能感知通过生成代理类来配置属性。
Mike, I believe what you observed is true. I am working with a ProfileProvider that uses Azure TableStorage as data store. I wanted to get a list of user profiles from database and merge them with information from membership provider.
It took some time until I realized that calling ProfileBase.Create() with a username as argument performs a lookup against TableStorage and actually retrieves the data associated with that username. As far as I'm concerned, calling this method Create() is misleading, I would expect Load() or Get().
Currently my code looks like this:
Is there a better (more straightforward, more performant) way to
I have had a look at Web Profile Builder but IMO this only provides design-time intellisense for custom profile properties by generating a proxy class.
在调用
保存
:You don't persist to the database until you call
Save
: