Well, you could do:
// It's not clear from your example what the type of Data should
// be; adjust accordingly.
var variable1 = Enumerable.Repeat(new { Data = 0 }, 0).AsQueryable();
if (something == 0)
{
//DB = DatabaseObject
variable1 = from a in DB.Table
select new {Data = a};
}
int rowTotal = variable1.Count();
This is effectively "typing by example". To be honest, I'd try to avoid it - but it's hard to know exactly how I'd do so without seeing the rest of the method. If possible, I'd try to keep the anonymous type scope as tight as possible.
Note: in this case you could just select a
instead of an anonymous type. I'm assuming your real use case is more complex. Likewise if you genuinely only need the row total, then set that inside the braces. The above solution is only applicable if you really, really need the value of the variable later on.