Windows Phone 7.5-本地SQL数据库 [英] Windows Phone 7.5 - Local SQL Database
问题描述
我正在创建WP7应用.
I am creating WP7 app.
在那个应用程序中,我使用LINQ to SQL创建本地数据库.我创建了一个像这样的类:
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();
}
但是这里我的问题是:在保存用户列表时,有诸如保存1天" ,"30天" 或永远"之类的单选框. 如果我选择一天",我必须将其保存1天,那么一天后应从本地数据库中删除用户;如果我选择"30天",则应在30天后将其删除,如果我选择永远" 它不应被删除.
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.
我该怎么做?
提前谢谢.
推荐答案
我将在表中添加另一列(有效期). 然后,我将通过一个简单的查询清除数据
I would add another column to the table(expiry date). And then, I would purge data with a Simple query
DELETE FROM User
WHERE (expiryDate < GETDATE())
您也可以在Linq2Sql中做到这一点
You can do this in Linq2Sql as well
这篇关于Windows Phone 7.5-本地SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!