none
Start using EF RRS feed

  • Question

  • Hello!

    I have created a DataMOdel from DB and now I have all tables from SQL server as Entities in my Solution. All my tables are listed as virtual DbSet in a class as following:

    public partial class MyProjectEntities : DbContext
        {
            public MyProjectEntities()
                : base("name=MyProjectEntities")
            {
            }
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                throw new UnintentionalCodeFirstException();
            }
        
            public virtual DbSet<Customer> Customer { get; set; }


    So far so good.

    Now I must start consuming data in entities and have some doubts.

    1. How to start consuming data from 

    public virtual DbSet<Customer> Customer { get; set; }

    I quess I must derive from

    MyProjectEntities

    and override virtual DbSet <Customer> 

    if I want to use Customer data from it? 

    Thanks!!!


    Thursday, March 27, 2014 3:15 PM

Answers

  • I suggest that you start simple by using a simple tutorial using the model first approach and then try to use the other approaches in using the Entity Framework. At the to of the link is the same tutorial is C#, but the C# version has lost the screen shots for the forms that need to be created when following the tutorial instructions.

    http://www.vbforums.com/showthread.php?540421-Tutorial-An-Introduction-to-the-ADO-NET-Entity-Framework

    Thursday, March 27, 2014 4:58 PM
  • Hello,

    >>1. How to start consuming data from

    First, create an instance of the MyProjectEntities as:

    MyProjectEntities db=new MyProjectEntities();

    The using codes like below to consume data:

    List< Customer > list=db. Customer.ToList();

    Now you will get the collection of Customer entity.

    If you are looking for tutorials with C#, you could check this link:

    http://adoeftutorial.codeplex.com/

    If you are looking for VB, darnold924s link is nice.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 28, 2014 7:08 AM
    Moderator

All replies

  • I suggest that you start simple by using a simple tutorial using the model first approach and then try to use the other approaches in using the Entity Framework. At the to of the link is the same tutorial is C#, but the C# version has lost the screen shots for the forms that need to be created when following the tutorial instructions.

    http://www.vbforums.com/showthread.php?540421-Tutorial-An-Introduction-to-the-ADO-NET-Entity-Framework

    Thursday, March 27, 2014 4:58 PM
  • Hello,

    >>1. How to start consuming data from

    First, create an instance of the MyProjectEntities as:

    MyProjectEntities db=new MyProjectEntities();

    The using codes like below to consume data:

    List< Customer > list=db. Customer.ToList();

    Now you will get the collection of Customer entity.

    If you are looking for tutorials with C#, you could check this link:

    http://adoeftutorial.codeplex.com/

    If you are looking for VB, darnold924s link is nice.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 28, 2014 7:08 AM
    Moderator
  • Hi,

    It seems to be a simple approach. The reason for my doubt was "virtual" in

    public virtual DbSet<Customer> Customer { get; set; }

    because I use to override all virtutal members prior to their usage.

    What about updating database with data added to Customer collection?

    Thanks:)


    • Edited by Muris Friday, March 28, 2014 8:37 AM
    Friday, March 28, 2014 8:32 AM
  • >> What about updating database with data added to Customer collection?

    It is simple, too. Look like below:

    MyProjectEntities db=new MyProjectEntities();
    
    Customer c=new Customer() {CustomerID = 1, CustomerName=”AAA”};
    
    db.Customers.Add(c);
    
    db.SaveChanges();
    

    You can get them from the links provided by me and darnold924 in actual.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 31, 2014 8:33 AM
    Moderator