Windows Phone 7.5 - 本地 SQL 数据库
我正在创建 WP7 应用程序。
在该应用程序中,我使用 LINQ to SQL 创建本地数据库。我创建了一个像这样的类:
[Table]
public class User
{
[Column(
IsPrimaryKey = true,
IsDbGenerated = true,
DbType = "INT NOT NULL Identity",
CanBeNull = false)]
public int Id { get; set; }
[Column]
public string FirstName { get; set; }
[Column]
public string LastName { get; set; }
}
并且我有如下所示的数据上下文:
public class UserDataContext : DataContext
{
public static string connString = "Data Source=isostore:/Users.sdf";
public UserDataContext(string connString)
: base(connString)
{ }
public Table<User> Users;
}
我使用下面的代码保存数据:
User user = new User
{
FirstName = tbFirstName.Text,
LastName = tbLastName.Text,
CreatedOn = DateTime.Now
};
using (var db = new UserDataContext(UserDataContext.connString))
{
db.Users.InsertOnSubmit(user);
db.SubmitChanges();
}
但这里我的问题是:在保存用户列表时,有像“保存1天”<这样的单选框/strong>、“30 天” 或 “永远”。 如果我选择“一天”,我必须将其保存 1 天,然后本地数据库中的用户应在一天后删除,如果我选择“30 天”,则应在 30 天后删除,如果我选择“永远” “它不应该被删除。
我该怎么做?
提前致谢。
I am creating WP7 app.
In that app i am using LINQ to SQL to create local database. I have created a class like this:
[Table]
public class User
{
[Column(
IsPrimaryKey = true,
IsDbGenerated = true,
DbType = "INT NOT NULL Identity",
CanBeNull = false)]
public int Id { get; set; }
[Column]
public string FirstName { get; set; }
[Column]
public string LastName { get; set; }
}
and I have data context like below:
public class UserDataContext : DataContext
{
public static string connString = "Data Source=isostore:/Users.sdf";
public UserDataContext(string connString)
: base(connString)
{ }
public Table<User> Users;
}
I am saving the data using below code:
User user = new User
{
FirstName = tbFirstName.Text,
LastName = tbLastName.Text,
CreatedOn = DateTime.Now
};
using (var db = new UserDataContext(UserDataContext.connString))
{
db.Users.InsertOnSubmit(user);
db.SubmitChanges();
}
But here my problem is: While saving the user list there is radioboxes like "Save for 1 Day", "30 days" or "forever". If i select "one day" i have to save it for 1 day then users from local database should be deleted after one day and if i select "30 days" it should be deleted after 30 days and if i select "forever" it should not be deleted.
How can i do this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会在表中添加另一列(到期日期)。
然后,我将使用简单查询清除数据
您也可以在 Linq2Sql 中执行此操作
I would add another column to the table(expiry date).
And then, I would purge data with a Simple query
You can do this in Linq2Sql as well