我想从最后一条记录中获取名为"Gram"的字段的值,并将其值放入变量中,而不使用任何条件.
首先我试过了
int value = int.Parse(Entity.TblGold.LastOrDefault().Gram.ToString());
Run Code Online (Sandbox Code Playgroud)
我试过第二次
int value = int.Parse(Entity.TblGold.Select(p => p.Gram).Last().ToString());
Run Code Online (Sandbox Code Playgroud)
我刚收到这个例外:
LINQ to Entities does not recognize the method 'DataModel.TblGold LastOrDefault[TblGold](System.Linq.IQueryable``1[DataModel.TblGold])' method, and this method cannot be translated into a store expression.
如何将List定义为struct的字段?
像这样的东西:
public struct MyStruct
{
public decimal SomeDecimalValue;
public int SomeIntValue;
public List<string> SomeStringList = new List<string> // <<I Mean this one?
}
Run Code Online (Sandbox Code Playgroud)
然后使用该字符串像这样:
Private void UseMyStruct()
{
MyStruct S= new MyStruct();
s.Add("first string");
s.Add("second string");
}
Run Code Online (Sandbox Code Playgroud)
我尝试过一些东西,但它们都会返回错误并且不起作用.
我正在尝试将我的错误写入MapPath中的文本文件中.但我有一个问题是:
path = Server.MapPath("~/emails.txt");
Run Code Online (Sandbox Code Playgroud)
实际上Server是在System.Web.UI.Page命名空间中我想在我的cs文件中使用它没有aspx文件...我的意思是它是AppCode中的CodeFile; 如何从cs CodeFile写入文件?