• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Another C# query (and believe me I have searched)"

Collapse

  • Scrag Meister
    replied
    Originally posted by RasputinDude View Post
    I don't have a .NET environment where I am at the moment so can't help.

    Does this help? c# - linq on nullable datetime - Stack Overflow
    Thanks, looks like I may have posted my edit when you posted your response.

    Have found a solution.
    Last edited by Scrag Meister; 15 November 2012, 08:33.

    Leave a comment:


  • RasputinDude
    replied
    I don't have a .NET environment where I am at the moment so can't help.

    Does this help? c# - linq on nullable datetime - Stack Overflow

    Leave a comment:


  • Scrag Meister
    replied
    Originally posted by Jaws View Post
    You can use a nullable datetime as below. Then later in your code you just include if (EndDate.HasValue) etc

    Code:
    var query = (
                                from MyTable in InTable.AsEnumerable()
                                group MyTable by MyTable.Field<String>("ClientAccountId") into g
    
                                select new
                                {
                                    Activity = OutputActivity,
                                    GroupMember = OutputGroupMember,
                                    BranchNo = OutputBranchNo,
                                    EarmarkingID = "",
                                    CounterpartyAcronym = GetClientMapping(ClientMapping, g.Key),
                                    ProductType = OutputProductType,
                                    StartDate = DateTime.Now,
                                    EndDate = new DateTime?()
                                 }
    It accepted the Nullable datetime at the point of assignment but later I get

    DataSet does not support System.Nullable<>

    A few articles mentioned implement some kind of extender? to handle this as the Dataset doesn't handle it by default. Will keep searching

    Edit : Found it, had to adjust my object shredder, that transfers my var Query to a DataTable. This is the change to allow use with Nullable fields. Will read it through in detail to understand what it does.


    Code:
    foreach (PropertyInfo p in type.GetProperties())
                {
    
                    if (!_ordinalMap.ContainsKey(p.Name))
                    {
    
                        Type colType = p.PropertyType;
    
                        if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                        {
    
                            colType = colType.GetGenericArguments()[0];
    
                        }
    
                        DataColumn dc = table.Columns.Contains(p.Name) ? table.Columns[p.Name]
    
                            : table.Columns.Add(p.Name, colType);
    
                        _ordinalMap.Add(p.Name, dc.Ordinal);
    
                    }
    
                }
    Last edited by Scrag Meister; 14 November 2012, 17:04.

    Leave a comment:


  • Jaws
    replied
    Originally posted by Scrag Meister View Post
    I have a LINQ query that I need to insert null dates into.

    var query = (
    from MyTable in InTable.AsEnumerable()
    group MyTable by MyTable.Field<String>("ClientAccountId") into g

    select new
    {
    Activity = OutputActivity,
    GroupMember = OutputGroupMember,
    BranchNo = OutputBranchNo,
    EarmarkingID = "",
    CounterpartyAcronym = GetClientMapping(ClientMapping, g.Key),
    ProductType = OutputProductType,
    StartDate = DateTime.Now,
    EndDate = nulldate
    }

    Currently nulldate is a string containing "nulldate" that I interpret later in the process.

    Is there a way to actually have a null datetime value in the query result?

    Don't flame if you think you are doing my job for me, just FO and don't reply.

    Where's Gentile when you need her.
    You can use a nullable datetime as below. Then later in your code you just include if (EndDate.HasValue) etc

    Code:
    var query = (
                                from MyTable in InTable.AsEnumerable()
                                group MyTable by MyTable.Field<String>("ClientAccountId") into g
    
                                select new
                                {
                                    Activity = OutputActivity,
                                    GroupMember = OutputGroupMember,
                                    BranchNo = OutputBranchNo,
                                    EarmarkingID = "",
                                    CounterpartyAcronym = GetClientMapping(ClientMapping, g.Key),
                                    ProductType = OutputProductType,
                                    StartDate = DateTime.Now,
                                    EndDate = new DateTime?()
                                 }

    Leave a comment:


  • Scrag Meister
    started a topic Another C# query (and believe me I have searched)

    Another C# query (and believe me I have searched)

    I have a LINQ query that I need to insert null dates into.

    var query = (
    from MyTable in InTable.AsEnumerable()
    group MyTable by MyTable.Field<String>("ClientAccountId") into g

    select new
    {
    Activity = OutputActivity,
    GroupMember = OutputGroupMember,
    BranchNo = OutputBranchNo,
    EarmarkingID = "",
    CounterpartyAcronym = GetClientMapping(ClientMapping, g.Key),
    ProductType = OutputProductType,
    StartDate = DateTime.Now,
    EndDate = nulldate
    }

    Currently nulldate is a string containing "nulldate" that I interpret later in the process.

    Is there a way to actually have a null datetime value in the query result?

    Don't flame if you think you are doing my job for me, just FO and don't reply.

    Where's Gentile when you need her.
Working...
X