我得到了这个例外:
LINQ to Entities不支持指定的类型成员'付费'.仅支持初始值设定项,实体成员和实体导航属性.
public ActionResult Index()
{
var debts = storeDB.Orders
.Where(o => o.Paid == false)
.OrderByDescending(o => o.DateCreated);
return View(debts);
}
Run Code Online (Sandbox Code Playgroud)
我的Model类
public partial class Order
{
public bool Paid {
get {
return TotalPaid >= Total;
}
}
public decimal TotalPaid {
get {
return Payments.Sum(p => p.Amount);
}
}
Run Code Online (Sandbox Code Playgroud)
付款是一个包含字段数量的相关表格,如果我删除Where子句显示有关付款的正确信息,查询有效,任何线索有什么问题?
解决了如下建议的答案:
public ActionResult Index()
{
var debts = storeDB.Orders
.OrderByDescending(o => o.DateCreated)
.ToList()
.Where(o => o.Paid == false);
return View(debts);
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
[DisplayName("58.Date and hour of birth")]
[DataType(DataType.DateTime, ErrorMessage = "Please enter a valid date in the format dd/mm/yyyy hh:mm")]
[Range(typeof(DateTime), "1/1/2011", "1/1/2016")]
[RequiredToClose]
public object V_58 { get; set; }
Run Code Online (Sandbox Code Playgroud)
我想强制包含时间(格式为hh:mm)而不仅仅是日期.此代码将1/1/2011视为有效,因为它不包含小时,有关如何表达正确格式的任何线索?(dd/mm/yyyy hh:mm)
我有一个非常大的60+问题表单,用户可以开始填写,保存在任何时候并保持不变.表单可以从数据库重新加载并随时完成,然后关闭它.
我有以下型号:
public class Questionnaire{
[Required]
public string Question1 { get; set; }
[Required]
[Range(1, 10)]
public int Quesiton2 { get; set; }
public string Question3 {get;set}
}
Run Code Online (Sandbox Code Playgroud)
当用户决定保存表单并执行完整验证时,我需要部分验证我的模型,包括在用户选择关闭表单时验证所需的文件.
实施它的最佳方法是什么?
我有一个类方法:
public static class ProductExtensions {
public static decimal GetPrice(this Product product, Guid rateId) {
return product.Prices
.Where(p => p.Rate.RateId == rateId)
.Select(b => b.UnitPrice)
.DefaultIfEmpty(product.UnitPrice)
.First();
}
}
Run Code Online (Sandbox Code Playgroud)
并评估表达
decimal? total =
(from cartItems in storeDB.Carts
where cartItems.CartId == shoppingCartId
select (int?)cartItems.Count * cartItems.Product.GetPrice(store.RateId))
.Sum();
Run Code Online (Sandbox Code Playgroud)
抛出异常:
LINQ to Entities无法识别方法'System.Decimal GetPrice(System.Guid)'方法,并且此方法无法转换为商店表达式.
我在其他地方使用这个相同的代码,工作得很好:
// Get the price for given rate
decimal price = product.GetPrice(rate.RateId);
Run Code Online (Sandbox Code Playgroud)
知道怎么解决吗?
我有以下类将数据导出到CSV:
public class CsvResult<T> : FileResult where T : class
{
private const string SEPARATOR = ",";
public IEnumerable<T> Data { get; private set; }
public Func<T, string>[] Columns { get; private set; }
public CsvResult(IEnumerable<T> data, params Func<T, string>[] columns)
: base("text/csv")
{
Data = data;
Columns = columns;
FileDownloadName = "Export.csv";
}
protected override void WriteFile(HttpResponseBase response)
{
response.ContentType = "text/csv";
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", FileDownloadName));
WriteColumns(response);
WriteData(response);
}
private void WriteData(HttpResponseBase response)
{
foreach (var dataItem in Data) …
Run Code Online (Sandbox Code Playgroud) 我有以下集团
class DeviceBloc extends Bloc<DeviceEvent, DeviceState> {
DataRepository repository;
DeviceBloc({@required this.repository}) : super(DeviceInitialState()) {
on<FetchDevicesEvent>(onFetchResources);
}
Future<void> onFetchResources(
FetchDevicesEvent event, Emitter<DeviceState> emit) async {
emit.call(DeviceLoadingState());
try {
List<DeviceResource> devices = await repository.getResources(event.type);
emit.call(DeviceLoadedState(devices: devices));
} catch (e) {
emit.call(DeviceErrorState(message: e.toString()));
}
}
}
Run Code Online (Sandbox Code Playgroud)
当触发 FetchDevicesEvent 事件时,它会启动一个长时间运行的任务,如果在运行任务完成之前收到其他 FetchDevicesEvent 事件,则会将错误结果返回给调用者。如何挂起等待的任务,并在收到新的 FetchDevicesEvent 后立即启动新的任务?
asp.net-mvc ×2
c# ×2
linq ×2
.net ×1
asynchronous ×1
bloc ×1
datetime ×1
flutter ×1
lambda ×1
validation ×1