Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: Saving an array to disk Pin
Member 1171394212-Jul-15 6:05
Member 1171394212-Jul-15 6:05 
QuestionHow to update database when adding an item Pin
Member 1183153312-Jul-15 5:15
Member 1183153312-Jul-15 5:15 
AnswerRe: How to update database when adding an item Pin
OriginalGriff12-Jul-15 5:46
mveOriginalGriff12-Jul-15 5:46 
GeneralRe: How to update database when adding an item Pin
Member 1183153312-Jul-15 5:53
Member 1183153312-Jul-15 5:53 
AnswerRe: How to update database when adding an item Pin
Dave Kreskowiak12-Jul-15 6:26
mveDave Kreskowiak12-Jul-15 6:26 
GeneralRe: How to update database when adding an item Pin
Member 1183153312-Jul-15 7:00
Member 1183153312-Jul-15 7:00 
QuestionLinq-ToSql and EF Questions Pin
Kevin Marois10-Jul-15 4:54
professionalKevin Marois10-Jul-15 4:54 
AnswerRe: Linq-ToSql and EF Questions Pin
Richard Deeming10-Jul-15 5:54
mveRichard Deeming10-Jul-15 5:54 
1) & 2) Both use ADO.NET behind the scenes. They use ExecuteReader / IDataReader to read the records and convert them into entity objects, which avoids keeping two copies of the data in memory.

3) EF tracks changes at the property level. You can access this information by calling:
C#
DbPropertyEntry entry = context.Entry(yourEntity).Property("PropertyName");
object currentValue = entry.CurrentValue;
object originalValue = entry.OriginalValue;
bool isModified = entry.IsModified;

DbPropertyValues databaseValues = entry.GetDatabaseValues();
object valueCurrentlyInTheDatabase = databaseValues["PropertyName"];



4) & 5) If your POCO classes match the database exactly, and have sensible property names, you should be able to use them without any changes. You might want to mark the properties as virtual, to allow lazy-loading of collections, but you shouldn't need to add any DB code.

If the classes don't match exactly, then you need to set up a mapping. You can either do this by adding annotation attributes to the properties[^] in the class; creating a separate meta-data class with the attributes, and adding the MetadataType attribute to your real class; or using the fluent mapping API[^].

Typically, using the existing POCOs would be as simple as:
C#
public class YourContext : DbContext
{
    public DbSet<Foo> Foos
    {
        get { return Set<Foo>(); }
    }
    
    public DbSet<Bar> Bars
    {
        get { return Set<Bar>(); }
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Linq-ToSql and EF Questions Pin
Kevin Marois10-Jul-15 5:56
professionalKevin Marois10-Jul-15 5:56 
Questionwifi form Pin
Member 118239158-Jul-15 16:51
Member 118239158-Jul-15 16:51 
AnswerRe: wifi form Pin
Dave Kreskowiak8-Jul-15 17:22
mveDave Kreskowiak8-Jul-15 17:22 
QuestionCasting HttpRequestMessage.Properties["MS_RequestContext"] to OwinHttpRequestContext Pin
Alaric_8-Jul-15 11:09
professionalAlaric_8-Jul-15 11:09 
QuestionSelectSingleNode issue Pin
tiwal7-Jul-15 7:42
tiwal7-Jul-15 7:42 
QuestionRe: SelectSingleNode issue Pin
ZurdoDev7-Jul-15 7:50
professionalZurdoDev7-Jul-15 7:50 
AnswerRe: SelectSingleNode issue Pin
tiwal7-Jul-15 8:25
tiwal7-Jul-15 8:25 
AnswerRe: SelectSingleNode issue Pin
Richard Deeming7-Jul-15 8:36
mveRichard Deeming7-Jul-15 8:36 
GeneralRe: SelectSingleNode issue Pin
tiwal7-Jul-15 9:08
tiwal7-Jul-15 9:08 
GeneralRe: SelectSingleNode issue Pin
Dave Kreskowiak7-Jul-15 9:12
mveDave Kreskowiak7-Jul-15 9:12 
GeneralRe: SelectSingleNode issue Pin
tiwal7-Jul-15 9:40
tiwal7-Jul-15 9:40 
GeneralRe: SelectSingleNode issue Pin
Dave Kreskowiak7-Jul-15 10:02
mveDave Kreskowiak7-Jul-15 10:02 
GeneralRe: SelectSingleNode issue Pin
tiwal7-Jul-15 10:07
tiwal7-Jul-15 10:07 
GeneralRe: SelectSingleNode issue Pin
Richard Deeming7-Jul-15 10:10
mveRichard Deeming7-Jul-15 10:10 
GeneralRe: SelectSingleNode issue Pin
tiwal7-Jul-15 10:21
tiwal7-Jul-15 10:21 
GeneralRe: SelectSingleNode issue Pin
Richard Deeming7-Jul-15 11:26
mveRichard Deeming7-Jul-15 11:26 
GeneralRe: SelectSingleNode issue Pin
tiwal7-Jul-15 21:02
tiwal7-Jul-15 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.