我得到了这个例外:
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) 我在Visual Studio 2012中使用了Entity Framework.通过"逆向工程代码优先"构建实体模型.
但是当我刚刚设置Visual Studio 2015,并通过NuGet设置EF电源工具时,我找不到"逆向工程师代码优先"选项.
谁知道我应该怎么做?
谢谢!
我的MVC应用程序中有两个实体,我使用Entity Framework 6 Code First方法填充数据库.学生实体中有两个城市ID; 其中一个为BirthCity,另一个为WorkingCity.当我在上面定义外键时,在迁移后在Student表中创建一个名为City_ID的额外列.我有错误或如何定义这些FK?提前致谢.
学生:
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public int BirthCityID { get; set; }
public int LivingCityID { get; set; }
[ForeignKey("BirthCityID")]
public virtual City BirthCity { get; set; }
[ForeignKey("LivingCityID")]
public virtual City LivingCity { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
市:
public class City
{
public int ID { get; set; }
public string CityName …Run Code Online (Sandbox Code Playgroud) asp.net-mvc entity-framework foreign-keys foreign-key-relationship ef-code-first
我正在尝试更新记录,之后我收到此错误消息 context.SaveChanges();
属性"name"是对象的关键信息的一部分,不能修改.
以下是更新功能的代码:
if (context.EAT_SourceNames.Any(e => e.name == newSourceName))
{
MessageBox.Show("Name already exists in the Database");
}
else
{
var nameToUpdate = context.EAT_SourceNames.SingleOrDefault(e => e.name == sourceName.name);
if (nameToUpdate != null)
{
nameToUpdate.name = newSourceName;
context.SaveChanges();
RefreshDGVs();
}
}
Run Code Online (Sandbox Code Playgroud)
我的SourceNames课程如下:
public EAT_SourceNames()
{
this.EAT_Sources = new ObservableListSource<EAT_Sources>();
}
public string name { get; set; }
public string version_id { get; set; }
public string allocation_name { get; set; }
Run Code Online (Sandbox Code Playgroud)
我搜索了类似的问题,但找不到任何有效的解决方案.
我是Entity Framework中Code-First方法的新手.我对如何做到这一点感到有点困惑:
我需要一个FK关系到同一个表,所以我可以在元素之间有一个Parent - > Child关系.
这是表的模型:
public class BucketGroup
{
public int Id {get;set;} // This is the PK in the Table
public string Name {get;set;}
// Now this the FK, to this Same Table:
public int? BucketGroupId {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
所以我把这个项目设为Nullable,如果BucketGroupId是NULL,那么我知道它是一个父项.
我创建了一个测试项目并使用Database First,模型是这样的:
public partial class Testing
{
public Testing()
{
this.Testing1 = new HashSet<Testing>();
}
public int Id { get; set; }
public Nullable<int> ParentId { get; set; }
public virtual ICollection<Testing> Testing1 { get; set; …Run Code Online (Sandbox Code Playgroud) 有没有人知道是否可以根据类的命名空间设置代码的表模式第一类?
例如,命名空间中的每个类Core.Foo都有一个模式Foo.
现在我读了"ASP.NET MVC 5,Freeman"一书,我创建了3个项目:
使用NuGet命令行我安装了很多软件包,如书中所示:
安装包Microsoft.Aspnet.Mvc -version 5.0.0.0 -projectname SportsStore.Domain ..等..
但我认为我安装错了,因为现在我有错误:
构建"SportsStore.WebUI,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"使用比程序集更高版本的"System.Web.Mvc,Version = 5.2.2.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35" System.Web.Mvc,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35",引用c:\ Users \Дима\ Documents\Visual Studio 2013\Projects\SportsStore\SportsStore.WebUI\bin\SportsStore .WebUI.dll SportsStore.UnitTests
无法理解,如何解决它
我正在尝试使用 redux saga 库来捕获一些操作,但是在运行应用程序时出现此错误:
index.js:2178 在 rootSaga 在 projectSaga 在 watchFetchRequest at takeEvery 的 rootSaga 中未被捕获 错误:take(patternOrChannel): 参数 8 不是有效的通道或有效的模式 ( http://localhost:3000/static/js/bundle。 js:84689:9 ) 在 takeEvery ( http://localhost:3000/static/js/bundle.js:85993:94 ) 在 createTaskIterator ( http://localhost:3000/static/js/bundle.js:85179: 17 ) 在 runForkEffect ( http://localhost:3000/static/js/bundle.js:85583:24 ) 在 runEffect ( http://localhost:3000/static/js/bundle.js:85468:872 ) 在 next ( http://localhost:3000/static/js/bundle.js:85348:9 ) 在 proc (http://localhost:3000/static/js/bundle.js:85303:3 ) 在 runForkEffect ( http://localhost:3000/static/js/bundle.js:85587:19 ) 在 runEffect ( http:// localhost:3000/static/js/bundle.js:85468:872 ) at http://localhost:3000/static/js/bundle.js:85677:14 at Array.forEach () at runAllEffect ( http://localhost :3000/static/js/bundle.js:85676:10 ) 在 runEffect ( …
情况就是这样.有两种类型的ElectricConsumer ie CommercialConsumers&DomesticConsumers(Quaters),一种Quater分配给一种Employee.下面是我的代码但遇到异常.
无法确定EFcodefirstDemo.CodeFistModel.Quater和EFcodefirstDemo.CodeFistModel.Employee类型之间关联的主要结尾.必须使用关系流畅API或数据注释显式配置此关联的主要结尾.
我知道我在某些地方犯错误,因为我是EF的新手.希望你能解决这个问题.
public class Employee
{
public Employee()
{
MeterReadings = new List<MeterReading>();
MeterReadings = new List<MeterReading>();
}
[Key]
[Column(Order = 1)]
public int EmployeeID { get; set; }
[Key]
[Column(Order = 2)]
public Int64 EmployeeNo { get; set; }
public String EmployeeName { get; set; }
[DefaultValue(true)]
public bool Gender { get; set; }
[DefaultValue(true)]
public bool HasResidence { get; set; }
public bool IsInDivision { get; set; }
public …Run Code Online (Sandbox Code Playgroud) c# entity-framework one-to-one ado.net-entity-data-model ef-code-first
你如何在linq中实现以下目标?我觉得应该有一个Linq替代方案.
var foods = new Dictionary<string, List<string>>();
foods.Add("Cake", new List<string>() { "Sponge", "Gateux", "Tart" });
foods.Add("Pie", new List<string>() { "Mud", "Apple" });
foods.Add("Roll", new List<string>() { "Sausage" });
var result = new List<Tuple<string, string>>();
foreach (var food in foods)
{
foreach (var detail in food.Value)
{
result.Add(new Tuple<string, string>(food.Key, detail));
}
}
ie
cake <sponge, gateux>
pie <apple>
to
cake, sponge
cake, gateux
pie, apple
Run Code Online (Sandbox Code Playgroud)
谢谢
c# ×5
asp.net-mvc ×2
linq ×2
dictionary ×1
flatten ×1
foreign-keys ×1
javascript ×1
one-to-one ×1
react-redux ×1
reactjs ×1
redux-saga ×1
typescript ×1