我有一个使用C#,WPF,ASP.NET WebAPI和实体框架的客户端/服务器解决方案.客户端和服务器分支在他的项目中共享模型.现在我正在尝试创建一个新客户端,使用Xamarin Forms并共享模型,但实体框架属性(MaxLength,Index,NotMapped等)在PCL中不兼容.所以这就是我尝试过的事情:
将Microsoft.EntityFrameworkCore导入PCL模型
如here所述,您应该能够将实体框架与Xamarin表单一起使用,因此我将PCL转换为NetStandard 1.3,并且它可以工作,允许每个...
使用DbInterception add方法注册时,IDbCommandInterceptor实例是否被认为是线程安全的?我实现了一个符合IDbCommandInterceptor接口的类,并且在跟踪调用其中一种执行方法时的命令开始时间与调用相应已执行方法时的停止时间相比,正在跟踪命令的开始时间.我将此信息存储在一个私有ivar列表中,需要知道我在做什么是否安全.解决方法:事实证明,IDbCommandInterceptor不是线程安全的,因为它仅被实例化一次.
我的代码中出现以下异常.An exception of type ‘System.InvalidOperationException’ occurred in EntityFramework.dll but was not handled in user code.
Additional information: The entity type user is not part of the model for the current context.以下是我的注册控制器.using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;namespace Registration2.Controll...
我有一个UWP(Windows 10)应用程序,可以在调试模式下完美运行(禁用.NET Native).
当我在发布模式下运行它时(或在带有.NET Native编译的调试模式下,我在返回context.Set().ToList();行上收到错误.public IEnumerable<TMobileEntity> ReadAll(){using (var context = new DataContext(database.DatabasePath)){return context.Set<TMobileEntity>().ToList();}}这是例外详情{System.TypeInitializationException: A type initializer ...
我有以下情况:
>实体是从数据库中加载的.>其中之一以表格(WPF用户控件)的形式呈现给用户,用户可以在其中编辑该实体的属性.>用户可以决定将更改应用到实体或取消编辑.
我将如何使用EntityFramework实现类似的东西?
我的问题是,当我将UI直接绑定到实体的属性时,所有更改都会立即应用于实体.我想将其推迟到用户按下OK并成功验证实体的那一刻.
我曾考虑过使用NoTracking加载实体,并在分离的实体经过验证后调用ApplyPropertyChanges,但...
我正在尝试使用PostgresSQL和Entity框架使用WebAPI配置ASP.NET 4.5.我发现Postgres驱动程序Npgsql有两个独立的版本.版本2.0.12.0支持EF 5.0.0.0.有一个单独的版本(根据文档错误标记为2.0.13.91)支持EF 6.0.0.0.我不关心我使用哪个版本,只要我能让它正常工作.我尝试使用EF 6.0.0.0时遇到错误,我正在尝试使5.0.0.0正常工作(6.0.0.0中的错误是一个单独的问题,如有必要,我会单独发布).
现在的问题是,显然因为我已经安装了EF 6.0.0.0,我...
我有100行不同日期的数据.我希望将结果按每30分钟相同的日期进行分组.
代替:结果1,2016-02-02 13:00:24结果1,2016-02-02 13:01:24结果1,2016-02-02 13:02:24结果1,2016-02-02 13:33:24
需要:
结果1,2016-02-02 13:00:24结果1,2016-02-02 13:33:24
原始查询:return await loc.Where(p => p.ReadTime >= df && p.ReadTime <= dt).OrderBy(p => p.ReadTime).ProjectTo<LocationModel>().ToListAsync();我尝试了什么:return await ...
我的数据模型有很多嵌套实体,我想热切地加载整个对象树…除了将按需显式加载的视图实体.
使用包含路径我必须指定许多路径,每次添加新实体时,我都必须调整这些包含路径.我目前使用我的存储库的以下方法来加载一个类型的所有实体:public virtual IQueryable<TEntity> All(string commaSeperatedIncludePropertyPaths = ""){IQueryable<TEntity> initialQuery = Context.Set<TEntity>();string[] includePaths = commaSeperatedInclu...
首先,我使用的是.Net 3.5 SP1.我有一些相关的实体如下.工程师有很多任命预约有很多工程师时代节目有很多约会我在我的数据访问层中提供功能来撤消/放弃对实体所做的更改.我这样做是打电话给…ObjectContext.Refresh(RefreshMode.StoreWins, Entity entity);这适用于实体本身以及任何1到多个关系,如Timeslot,但不会还原对多对多关系的任何更改.
我如何回过头来改变多对多关系,最好是在通用庄园中,因为我的DiscardChanges()函数目前在...
我看到很多人都在问一个类似的问题,但不是这个问题.我正在尝试用POCO代理做我希望相对简单的事情.using (var context = new MyObjectContext())
{context.ContextOptions.ProxyCreationEnabled = true;// this does indeed create an instance of a proxy for me...// something like Product_SomeBunchOfNumbersForProxyvar newEntity = context.CreateObject<MyEntity>();// throws exception because newEntity is not in Objec...
执行此代码时收到此错误:[HttpPost]public ActionResult Registration(UserModel user){Console.WriteLine("ja");try{if (ModelState.IsValid){var crypto = new SimpleCrypto.PBKDF2();var encrpPass = crypto.Compute(user.Password);UserModel newUser = new UserModel(user.Email, encrpPass);newUser.PasswordSalt = crypto.Salt;userRepository.Add(newUser);userRepository.SaveChanges();return RedirectToAction("Index"...
我正在尝试在EntityFramework CodeFirst中编辑数据透视表的内容.
我正在使用.NET Framework 4.6.1和EntityFramework 6.1.3.
我的模型设置如下:public class Post
{/// <summary>/// The post's id in the database/// </summary>public int Id { get; set; }/// <summary>/// The the categories the post belongs to/// </summary>[InverseProperty("Posts")]public virtual ICollection<Category> Categories { get; set; }/// ...
有没有办法在运行时获取EF的版本?类似的东西Console.WriteLine(Environment.Version);将返回4.0.30319.18034解决方法:扩展阿列克谢的想法,你可以做到string version = typeof(DbSet).Assembly.GetName().Version.ToString();
我有这门课:public class Message
{public long Id { get; set; }public string Subject { get; set; }public string Message { get; set; }public virtual Message ParentMessage { get; set; }public virtual Message ChildMessage { get; set; }//...
}使用EntityFramework Code First Add-Migration为我提供了以下消息:无法确定类型之间关联的主要结束…
我不能使用[Required]属性,因为这个线程中的第一条消息没有父节点,线程...
我们正在研究一个性能问题,其中EF 6.1.3速度很慢,我们无法弄清楚可能导致它的原因.
数据库上下文初始化为:Configuration.ProxyCreationEnabled = false;
Configuration.AutoDetectChangesEnabled = false;
Configuration.ValidateOnSaveEnabled = false;我们已将性能问题与以下方法隔离开来:protected virtual async Task<long> UpdateEntityInStoreAsync(T entity,string[] changedProperties)
{using (var session = sessionFa...