我陷入了一个奇怪的问题。我有一个CashGameGeneralViewModel
类至极看起来像这样linq查询中的String.Format
public class CashGameGeneralViewModel
{
public string Limit { get; set; }
public int HandsPlayed { get; set; }
public float AmountWon { get; set; }
}
这里是应该返回由某个播放器播放所有手中的方法:
public List<CashGameGeneralViewModel> GetAllHands(string playerToFind)
{
HoldemHandContext db = new HoldemHandContext();
int playerId = GetPlayerId(playerToFind);
var holdemHandResult = (from phh in db.PlayersInHoldemHands
from hh in db.HoldemHands
where hh.Id == phh.HandPlayed && phh.PlayerId == playerId
select new CashGameGeneralViewModel()
{
Limit = //"some text",
String.Format("{0:0.00}", hh.SBlindAmount) + "/" +
String.Format("{0:0.00}", hh.BBlindAmount),
HandsPlayed = db.HoldemHands.Distinct().Count(),
AmountWon = 0
}
).ToList();
return holdemHandResult;
}
public int GetPlayerId(string playerToFind)
{
HoldemHandContext db = new HoldemHandContext();
int playerId = (from p in db.Players
where p.ScreenName == playerToFind
select p.Id).FirstOrDefault();
return playerId;
}
现在的问题是
Limit = //"some text",
String.Format("{0:0.00}", hh.SBlindAmount) + "/" +
String.Format("{0:0.00}", hh.BBlindAmount)
部分。 hh.SBlindAmount
和hh.BBlindAmount
是浮点值。我想使用String.Format
,因为0.10
被缩短为0.1
,并以字符串格式获得它,就像我想要的那样。但我得到一个例外说,'The invocation of the constructor on type 'PokerRecord.View.CashGameGeneralUC' that matches the specified binding constraints threw an exception.' Line number '60' and line position '18'.
。当我删除string.format并放入一些“常规”字符串时,一切正常......任何人都知道为什么?
你有应该有ABO更多信息InnerException属性除外真正的问题。你检查过了吗? – Tim 2011-05-17 18:51:21
只是看了起来,现在我有另一个问题...内部异常是'LINQ to Entities不能识别'System.String格式(System.String,System.Object)'方法的方法,并且此方法无法翻译进入一个商店的表达。“我怎么能得到字符串格式,因为我想在这里? – 2011-05-17 18:54:31
我会尝试下面的AllenG的答案,看看是否更好。我想LinQ to Entities试图在其实际处理的查询中使用string.format函数,而不是在事后处理。 AllenG的方式可能会解决这个问题,我不确定。 – Tim 2011-05-17 18:57:01