Click here to Skip to main content
15,913,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: split method bug Pin
eddieangel22-Sep-17 6:42
eddieangel22-Sep-17 6:42 
GeneralRe: split method bug Pin
WoodChuckChuckles22-Sep-17 7:56
WoodChuckChuckles22-Sep-17 7:56 
GeneralRe: split method bug Pin
eddieangel22-Sep-17 8:13
eddieangel22-Sep-17 8:13 
QuestionI wants to show a stack panel using the TextBlock controls for the MyNotes about box. Which of the following code will help for me ? Pin
Member 1309368222-Sep-17 0:19
Member 1309368222-Sep-17 0:19 
AnswerRe: I wants to show a stack panel using the TextBlock controls for the MyNotes about box. Which of the following code will help for me ? Pin
OriginalGriff22-Sep-17 0:53
mveOriginalGriff22-Sep-17 0:53 
AnswerRe: I wants to show a stack panel using the TextBlock controls for the MyNotes about box. Which of the following code will help for me ? Pin
Pete O'Hanlon22-Sep-17 2:09
mvePete O'Hanlon22-Sep-17 2:09 
QuestionI wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Member 1309368221-Sep-17 22:59
Member 1309368221-Sep-17 22:59 
AnswerRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Eddy Vluggen21-Sep-17 23:15
professionalEddy Vluggen21-Sep-17 23:15 
AnswerRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
OriginalGriff21-Sep-17 23:18
mveOriginalGriff21-Sep-17 23:18 
AnswerRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Jochen Arndt22-Sep-17 0:17
professionalJochen Arndt22-Sep-17 0:17 
GeneralRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Rob Philpott22-Sep-17 0:19
Rob Philpott22-Sep-17 0:19 
GeneralRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Jochen Arndt22-Sep-17 0:23
professionalJochen Arndt22-Sep-17 0:23 
GeneralRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Rob Philpott22-Sep-17 1:15
Rob Philpott22-Sep-17 1:15 
QuestionImplementing a COM Message Filter, it always fails... Pin
Joan M21-Sep-17 5:57
professionalJoan M21-Sep-17 5:57 
SuggestionRe: Implementing a COM Message Filter, it always fails... Pin
Richard Deeming21-Sep-17 6:14
mveRichard Deeming21-Sep-17 6:14 
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 

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.