Specifying StagingMessageFields.ScheduledTime in the query will simply result in the field, not the cast. So you have to direct the linq provider to add the cast. So the function mapping should be something like CAST({0} as bigint).
I see you're using queryspec, I overlooked this, I assumed you were using Linq and I sent you to the wrong spot. Sorry for that. (you posted this in the linq forum, hence my confusion)
In QuerySpec you can either define a DbFunctionCall predicate directly, or define a functionmappingexpression.
A DbFunctionCall expression is a little awkward looking, as it falls back onto the old low-level API. It still is OK to know how it works though.
var q2 = qf.StagingMessage
.From(QueryTarget.LeftJoin(StagingMessageEntity.Relations.SubmitMessageEntityUsingStagingMessageId)).
Where(
(
(qf.Field("ScheduledTime").SetExpression(new DbFunctionCall("CAST({0} as bigint)", StagingMessageFields.ScheduledTime)) < 1000000000)
.And(StagingMessageFields.DateTime < DateTime.Now).And(StagingMessageFields.DateTime > DateTime.Now.AddDays(-100)).And(SubmitMessageFields.Id == System.DBNull.Value)
);
Another, more cleaner alternative, is using a function mapping. You first define the function mapping:
public class MyFunctionMappings : FunctionMappingStore
{
public MyFunctionMappings() : base()
{
this.Add(new FunctionMapping(typeof(MyFunctions), "CastToBigInt", 1, "Cast({0} as bigint)"));
}
}
And then you define the method. This is done a little different in queryspec than it is done in linq.
public class MyFunctions
{
public static FunctionMappingExpression CastToBigInt(IEntityFieldCore fieldToCast)
{
return new FunctionMappingExpression(typeof(MyFunctionMappings), "CastToBigInt", 1, fieldToCast);
}
}
You then use it like:
var q2 = qf.StagingMessage
.From(QueryTarget.LeftJoin(StagingMessageEntity.Relations.SubmitMessageEntityUsingStagingMessageId)).
Where(
(
(MyFunctions.CastToBigInt(StagingMessageFields.ScheduledTime) < 1000000000)
.And(StagingMessageFields.DateTime < DateTime.Now).And(StagingMessageFields.DateTime > DateTime.Now.AddDays(-100)).And(SubmitMessageFields.Id == System.DBNull.Value)
);
q2.CustomFunctionMappingStore = new MyFunctionMappings();
Not tested, but it should give you an idea how to get it working.