我正在使用EF CTP5代码优先使用Sql CE 4.0.我试图在两个DateTime属性之间执行时间不敏感的日期比较.
由于linq to entites无法解析DateTime.Date属性(本来不错),解决方案是使用EntityFunctions.TruncateTime,但这似乎不适用于Sql CE 4.0.
我可以手动比较这两个日期的年,月和日,这可行但是使代码比它应该更详细.理想情况下,我不想更改我的查询以使用长版本使它们与完整的sql server和sql ce 4.0一起使用.
因此,有没有人有任何干净,聪明的解决方案呢?我认为解决方案可能会涉及表达式重写,但我不太清楚从哪里开始.
任何帮助是极大的赞赏,
保罗
datetime linq-to-entities entity-framework sql-server-ce-4 entity-framework-ctp5
我在我的Windows应用程序中使用了SQL Server CE 4.0,并使用Entity Framework创建了它的模型.
它工作正常但我的问题是它没有构造函数来更改连接字符串,默认情况下它从app.config文件中读取连接字符串.
using (var Context = new MyEntitiesModel(//has no constructor))
{
...
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个动态连接字符串和
using (var Context = new MyEntitiesModel())
{
Context.Database.Connection.ConnectionString = entityConnection.ConnectionString;
}
Run Code Online (Sandbox Code Playgroud)
它通过这种方式工作正常,但如果我删除app.config文件中的另一个连接字符串,它给了我这个.
错误=无效的元数据....
因为默认构造函数使用它
我该怎么处理?
在过去的几个月里,我首次使用Entity Framework代码和sql server CE开发了一个应用程序.我发现2的组合非常有用,与我以前的做事方式(特别是ADO.NET)相比,它允许疯狂地更快的开发时间.
但是,今天早上我和一些同事遇到了一个问题,我们在任何有关SqlServer CE的文档中都没见过.它不能同时处理多个插入!
在我遇到这个问题之前,我认为CE可能成为我的首选数据库.我发现这个的原因是在我的应用程序中我需要立即向Web服务发出多个请求,并且它引入了一些瓶颈,所以我继续使用Parallel.Invoke调用来发出多个请求.
这一切都很好,直到我打开我的应用程序消息记录服务.此时我在发出Web请求时开始出现以下错误:
A duplicate value cannot be inserted into a unique index. [ Table name = Accounts,Constraint name = PK__Accounts__0000000000000016 ]
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlServerCe.SqlCeException: A duplicate value cannot be inserted into a unique index. [ Table name = Accounts,Constraint name = …Run Code Online (Sandbox Code Playgroud) 我有一个SQL SqlCeParameter语句例如:
mySQLCommand1.CommandText = @"
INSERT INTO clientSubjectiveComplaints (clientSubComplaintCreated)
VALUES (@ClientSubComplaintCreated)
";
Run Code Online (Sandbox Code Playgroud)
一旦INSERT成功,我需要返回自动生成的ID(INT主键),以便我可以在第二个INSERT语句中使用它.
这可能SqlCe吗?如果你能提供一个例子,请.
我首先在SQL ce 4.0中使用EF 4.1代码
我有两节课
public class Customer
{
public int ID { get; set; }
public string CompanyName { get; set; }
public List<ContactPerson> ContactPersons { get; set; }
}
public class ContactPerson
{
public int ID { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和DbContext
public class MyDB : DbContext
{
public DbSet<ContactPerson> ContactPersons { get; set; }
public DbSet<Customer> Customers { get; set; }
public MyDB()
{
this.Configuration.LazyLoadingEnabled = true;
}
protected override …Run Code Online (Sandbox Code Playgroud) 不使用SQL Profiler或EF Profiler等外部跟踪器.有没有一种方法可以使用EF 4.1针对SQL Server CE数据库跟踪下面的语句的SQL?
int count = context.Customers.Count();
Run Code Online (Sandbox Code Playgroud) 我正在使用Entity Framework代码和SQL Server Compact 4.0构建.NET 4 WPF应用程序.我正在尝试调用DbContext.SaveChanges()后台线程以避免阻止UI,但我偶尔会遇到以下异常:
System.AccessViolationException occurred
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=System.Data.SqlServerCe
StackTrace:
at System.Data.SqlServerCe.NativeMethodsHelper.OpenStore(IntPtr pOpenInfo, IntPtr pfnOnFlushFailure, IntPtr& pStoreService, IntPtr& pStoreServer, IntPtr& pQpServices, IntPtr& pSeStore, IntPtr& pTx, IntPtr& pQpDatabase, IntPtr& pQpSession, IntPtr& pStoreEvents, IntPtr& pError)
at System.Data.SqlServerCe.NativeMethods.OpenStore(IntPtr pOpenInfo, IntPtr pfnOnFlushFailure, IntPtr& pStoreService, IntPtr& pStoreServer, IntPtr& pQpServices, IntPtr& pSeStore, IntPtr& pTx, IntPtr& pQpDatabase, IntPtr& pQpSession, IntPtr& pStoreEvents, IntPtr& pError)
at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
at …Run Code Online (Sandbox Code Playgroud) c# multithreading entity-framework sql-server-ce sql-server-ce-4
好吧,这个让我很困惑,如果问题的标题不能准确描述我的问题,我会道歉.
我有一个用C#编写的程序,使用Entity Framework和SQL Server CE.我在Windows 7上开发它,它工作正常.我也有一台Windows 8.1机器,我已经测试过它,它也可以正常工作.
但是,在一些Windows 8.1计算机上,程序一旦尝试访问数据库就会崩溃.我收到以下错误:
未处理的异常:System.InvalidOperationException:找不到具有不变名称"System.Data.SqlServerCe.3.5"的ADO.NET提供程序的实体框架提供程序.确保提供程序已在应用程序配置文件的"entityFramework"部分中注册.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882.
现在,这真让我感到困惑,因为我在我的项目中安装了最新的SQL Server CE NuGet包(4.0).我使用SQL Server CE工具箱显式创建SQL Server CE 4.0数据库,我使用应用程序分发了4.0 dll,并且我明确地在my app.configfile(invariantName="System.Data.SqlServerCe.4.0")中列出了4.0版本.
那么,为什么错误说呢System.Data.SqlServerCe.3.5?为什么此错误仅发生在几台Windows 8.1计算机上?
(我还搜索了我的整个解决方案,文本"3.5"甚至没有出现在任何地方.)
我发现了类似的错误,我尝试(从 这个问题)包括这个:
private volatile Type _dependency;
public MyClass()
{
_dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}
Run Code Online (Sandbox Code Playgroud)
没有效果,我仍然得到同样的答案.
无论如何,如果有人有任何想法,我会非常感谢任何形式的投入.
问题
需要使用EF4 + SQL CE4将int转换为字符串.使用SqlFunctions.StringConvert(double)的推荐选项仍然给我错误.
选项1(原件).这给了我错误:
public static IEnumerable<SelectListItem> xxGetCustomerList()
{
using (DatabaseEntities db = new DatabaseEntities())
{
var list = from l in db.Customers
orderby l.CompanyName
select new SelectListItem { Value = l.CustomerID.ToString(), Text = l.CompanyName };
return list.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
选项2(大多数建议).然后很多帖子建议,我使用库System.Data.Objects.SqlClient中的SqlFunctions.StringConvert()函数:
public static IEnumerable<SelectListItem> GetCustomerList()
{
using (DatabaseEntities db = new DatabaseEntities())
{
var list = from l in db.Customers
orderby l.CompanyName
select new SelectListItem { Value = SqlFunctions.StringConvert((double)l.CustomerID), Text = l.CompanyName };
return list.ToList();
} …Run Code Online (Sandbox Code Playgroud) 我没有使用SQL CE 3.5 for Windows Mobile,因为我需要在我的应用程序设置中包含一些SQL CE 3.5的二进制文件(大小> 3 MB).
现在,我正在为Windows Phone 7开发.使用Mango realease,我们支持本地数据库.我们是否需要包含任何增加最终应用程序大小的二进制文件?如果是,那些二进制文件的足迹是什么?