none
EF Code First not work RRS feed

  • Question

  • using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
     
    public partial class peotri_entities : DbContext
    {
        public peotri_entities() : base("peotri_entities") { }
     
        public DbSet<user> user { get; set; }
    }


        public class user
        {
            public int id { get; set; }
            public string email { get; set; } 
            public string password { get; set; } 
            public DateTime add_dt { get; set; } 
            public DateTime logon_add_dt { get; set; }
        }


        public abstract class repository_abstractt<T> where T : class, new()
        {
            protected abstract peotri_entities  e { get; }
            protected abstract System.Data.Entity.DbSet<T> s { get; }
     
            public virtual System.Collections.Generic.IEnumerable<T> Get() { return s; }
            public virtual void Create(T imA) { s.Add(imA); e.SaveChanges(); }
            public virtual void Update(T imA) { s.Attach(imA); e.Entry(imA).State =     System.Data.EntityState.Modified; e.SaveChanges(); }
            public virtual void Delete(T imA) { s.Remove(imA); e.SaveChanges(); }
        }


        public sealed class user_repository : repository_abstractt<user>
        {
            peotri_entities ee = new peotri_entities();
            protected override peotri_entities e { get { return ee; } }
            protected override System.Data.Entity.DbSet<user> s { get { return ee.user; } }
        }

    <add name="peotri_entities" connectionString="Data Source=AYRA_NET;Initial Catalog=peotri;Integrated Security=True; providerName="System.Data.SqlClient" />



    if i'm create element and want write in databese i not have error but in db table my row is not write. if i'm read data from db table i have error not find elements return null collection. Help me please.
    Monday, March 18, 2013 12:22 AM

All replies

  • Hi Ayrat_net,

    Welcome to the MSDN forum.

    Could you please share the code snippet about creating elements and saving changes?

    I think the DbSet<User> in class repository_abstractt<T> and class user_repository are not required, because there is the DbSet<User> in class peotri_entities.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 19, 2013 8:38 AM