ASP.NET 会员资料
我想向今天生日的所有用户发送一封电子邮件,
我正在使用内置的 asp.net (3.5) 会员资格。所有用户都有一个配置文件(存储在 aspnet_Profile 中),其中包含名为“生日”的日期/时间属性。我需要从“aspnet_Membership”表中获取用户电子邮件地址列表(其中用户的生日是今天),以及用户“名字”(aspnet_Profile 表中的字符串属性)。
我希望最好使用 C# LINQ 返回一个列表。
我不确定如何根据配置文件表中的生日属性存储在数据库表中的方式(即名称/值列)来访问它
I want to send out an email to all users where their birthday is today
I am using the built-in asp.net (3.5) membership. All users have a profile (stored in aspnet_Profile) which contains a date/time property called 'birthday'. I need to get a list of users email addresses from the 'aspnet_Membership' table where a users birthday is today, along with the users 'firstname' which is string property in the aspnet_Profile table.
I would like a list returned preferrably using C# LINQ.
I am not sure how to access the birthday property in the profile table, based on the way it is stored in the db table i.e name/value columns
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您应该考虑更改为基于改进的表的提供程序:
http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx
这允许您以标准 SQL 方式将数据分成每个表列一个值。这比标准提供程序执行得更好,它解决了查询配置文件数据库的问题。
转换数据库需要少量工作,但在代码方面,只需在不同的提供程序中进行配置即可,其他任何内容都不应更改。这就是提供者模式的美妙之处。
I think you should consider changing to the much-improved table based provider:
http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx
This allows you to separate your data into one value per table column in the standard SQL way. This performs petter than the standard provider and it solves your problem of querying the Profiles database.
It will take a small amount of work to convert the database, but on the code side, it is just a matter of configuring in a different provider and nothing else should change. That is the beaurty of the provider pattern.
我使用 LINQ 的程度不足以给您一个好的答案,但以下可能是您需要的底层 SQL(这就是我的 SSMS 在查询设计器中生成它的方式):
I don't use LINQ enough to give you a good answer, but the following may be the underlying SQL you need (This is how my SSMS generated it in the query designer):
Profile 机制通过拆分每个名称/值对来解析值,然后单独解析它们。您可以自己编写代码来做到这一点。或者您可以遵循@Daniel 的方法并使用替代提供商,这使生活更轻松。开箱即用的提供程序在字符串连接方面很麻烦。
此代码在同一个应用程序中吗?如果您正在谈论 C#,您可以只使用配置文件对象来检索它...这段代码位于什么上下文中?批量服务?
The Profile mechanism parses the values out by splitting each name/value pair up, and then parsing them individually. You could write code to do that yourself. Or you could follow @Daniel's approach and use the alternative provider, which makes life easier. The out-of-the-box provider is a pain with the string concatenation.
Is this code in the same app? You could just use the profile object to retrieve it, if you are talking C#... what context is this piece of code in? Batch service?