Windows Phone 7.5 - Local SQL Database

╄→гoц情女王★ 提交于 2019-12-10 12:12:45

问题


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.


回答1:


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())

You can do this in Linq2Sql as well



来源:https://stackoverflow.com/questions/9292523/windows-phone-7-5-local-sql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!