Click here to Skip to main content
15,890,436 members
Home / Discussions / C#
   

C#

 
GeneralRe: Implementing a COM Message Filter, it always fails... Pin
Joan M21-Sep-17 6:21
professionalJoan M21-Sep-17 6:21 
GeneralRe: Implementing a COM Message Filter, it always fails... Pin
Richard Deeming21-Sep-17 6:37
mveRichard Deeming21-Sep-17 6:37 
GeneralRe: Implementing a COM Message Filter, it always fails... Pin
Joan M21-Sep-17 7:26
professionalJoan M21-Sep-17 7:26 
QuestionEntity Framework Questions - Round 1 Pin
Kevin Marois21-Sep-17 4:11
professionalKevin Marois21-Sep-17 4:11 
AnswerRe: Entity Framework Questions - Round 1 Pin
Nathan Minier21-Sep-17 4:46
professionalNathan Minier21-Sep-17 4:46 
GeneralRe: Entity Framework Questions - Round 1 Pin
Kevin Marois21-Sep-17 4:48
professionalKevin Marois21-Sep-17 4:48 
GeneralRe: Entity Framework Questions - Round 1 Pin
Nathan Minier21-Sep-17 5:19
professionalNathan Minier21-Sep-17 5:19 
AnswerRe: Entity Framework Questions - Round 1 Pin
C. David Johnson6-Oct-17 7:15
C. David Johnson6-Oct-17 7:15 
Depending on the Version of EF you have different "Mechanisms" but they all basically boil down to

Simple Poco Classes for each data type returned(table or stored procedure), and references to any linked tables.
Then there is the map file which defines the parameters and settings for each object (which columns are required, field sizes, single or many...

To be perfectly honest its my experience that EF is a cool toy for pulling reports or nested data (Pull a Customer and have all his orders in a single call)
HOWEVER if performance is in any way a consideration for the application Avoid EF like the plague.

I personally prefer to use parameterized stored procedure ADO DB calls, then inside my POCO classes I will add two methods called FromADO one takes a DataRow and the Other Takes a DataTable

public static List<Deposit> FromADO(DataTable objectsToConvert)
{
    return (from DataRow objectToConvert in objectsToConvert.Rows select FromADO(objectToConvert)).ToList();
}

public static Deposit FromADO(DataRow objectToConvert)
{
    var returned = new Deposit();
    if (objectToConvert.Table.Columns["ID"] != null && !string.IsNullOrEmpty(objectToConvert["ID"].ToString()))
        returned.ID = int.Parse(objectToConvert["ID"].ToString());
    if (objectToConvert.Table.Columns["DateTime"] != null && !string.IsNullOrEmpty(objectToConvert["DateTime"].ToString()))
        returned.DateTime = System.DateTime.Parse(objectToConvert["DateTime"].ToString());
    if (objectToConvert.Table.Columns["Description"] != null && !string.IsNullOrEmpty(objectToConvert["Description"].ToString()))
        returned.Description = objectToConvert["Description"].ToString();
    if (objectToConvert.Table.Columns["Total"] != null && !string.IsNullOrEmpty(objectToConvert["Total"].ToString()))
        returned.Total = double.Parse(objectToConvert["Total"].ToString());
    return returned;
}


What this accomplishes is any call that needs a Deposit you pass the DataTable or DataRow and you get a list or a single Deposit back.
Similarly your ORM class call becomes simple and easy to maintain

public Deposit GetDepositById(int id)
{
    var parms = new List<SqlParameter>
    {
        new SqlParameter {DbType = DbType.Int16, Value = id, Direction = ParameterDirection.Input, ParameterName = "@ID", SqlDbType = SqlDbType.Int}
    };
    var returned = ADOHelper.ReturnDataTable(conn, "sp_DepositGetById", parms, CommandType.StoredProcedure);
    return Deposit.FromADO(returned).FirstOrDefault();
}


And for a call the returns more than one deposit

public List<Deposit> GetDepositsByDateRange(DateTime begindate, DateTime enddate)
 {
    var parms = new List<SqlParameter>
    {
     new SqlParameter {DbType = DbType.DateTime, Value = begindate, Direction = ParameterDirection.Input, ParameterName = "@BeginDate", SqlDbType = SqlDbType.DateTime},
     new SqlParameter {DbType = DbType.DateTime, Value = enddate, Direction = ParameterDirection.Input, ParameterName = "@EndDate", SqlDbType = SqlDbType.DateTime}
    };
     var returned = ADOHelper.ReturnDataTable(conn, "sp_DepositsGetByDateRange", parms, CommandType.StoredProcedure);
     return Deposit.FromADO(returned);
 }



While not Sexy, flashy or new its fast stable and simple to maintain.. my two cents
GeneralRe: Entity Framework Questions - Round 1 Pin
Nathan Minier10-Oct-17 2:34
professionalNathan Minier10-Oct-17 2:34 
AnswerRe: Entity Framework Questions - Round 1 Pin
Gerry Schmitz21-Sep-17 13:05
mveGerry Schmitz21-Sep-17 13:05 
QuestionHow to save an excel file via network ? Pin
Member 1342184321-Sep-17 3:06
Member 1342184321-Sep-17 3:06 
GeneralRe: How to save an excel file via network ? Pin
Richard MacCutchan21-Sep-17 3:17
mveRichard MacCutchan21-Sep-17 3:17 
AnswerRe: How to save an excel file via network ? Pin
Eddy Vluggen21-Sep-17 6:28
professionalEddy Vluggen21-Sep-17 6:28 
AnswerRe: How to save an excel file via network ? Pin
Gerry Schmitz21-Sep-17 13:06
mveGerry Schmitz21-Sep-17 13:06 
Questionperformance counter in visual studio 217 C# Pin
AMMAR ALNAJIM20-Sep-17 20:41
AMMAR ALNAJIM20-Sep-17 20:41 
AnswerRe: performance counter in visual studio 217 C# Pin
Pete O'Hanlon20-Sep-17 21:10
mvePete O'Hanlon20-Sep-17 21:10 
AnswerRe: performance counter in visual studio 217 C# Pin
OriginalGriff20-Sep-17 22:59
mveOriginalGriff20-Sep-17 22:59 
AnswerRe: performance counter in visual studio 217 C# Pin
Eddy Vluggen20-Sep-17 23:20
professionalEddy Vluggen20-Sep-17 23:20 
QuestionC#-Form-DataGridView-Hangs Pin
Member 1341980320-Sep-17 3:05
Member 1341980320-Sep-17 3:05 
AnswerRe: C#-Form-DataGridView-Hangs Pin
Richard MacCutchan20-Sep-17 3:27
mveRichard MacCutchan20-Sep-17 3:27 
AnswerRe: C#-Form-DataGridView-Hangs Pin
Eddy Vluggen20-Sep-17 3:38
professionalEddy Vluggen20-Sep-17 3:38 
Questionmatching exact word c# Pin
Love Allah19-Sep-17 12:42
Love Allah19-Sep-17 12:42 
AnswerRe: matching exact word c# Pin
PIEBALDconsult19-Sep-17 12:45
mvePIEBALDconsult19-Sep-17 12:45 
GeneralRe: matching exact word c# Pin
Love Allah19-Sep-17 13:00
Love Allah19-Sep-17 13:00 
AnswerRe: matching exact word c# Pin
OriginalGriff19-Sep-17 20:02
mveOriginalGriff19-Sep-17 20: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.