昨天我将我的电脑从Windows 7"升级"到Windows 8,所以现在我正在使用Visual Studio 2012,并打开我的Visual Studio 2010项目.
这个项目总是工作正常,但它在Visual Studio 2012中不起作用.我有一些奇怪的错误,但我修复了这些.现在我留下了一个我无法修复但在Google上找不到的错误:
我得到这个例外:
无法将Database.DefaultConnectionFactory设置为应用程序配置中指定的'System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework'类型的实例.请参阅内部异常了解详细信
具有以下不足之处:
找不到类型'System.Data.Entity.Infrastructure.SqlConnectionFactory'的构造函数.
我的Web.Config看起来非常标准:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-WebUI-201253192737;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)
SqlConnectionFactory类存在,它有2个构造函数(一个无参数,一个接受连接字符串).我通过在C#代码中创建一个SqlConnectionFactory来测试它.
我已经删除了Entity Framework并重新安装了它,但这并没有解决问题.
我正在使用实体框架5.0 RC(在VS2010中如前所述)在SQL Server 2012 + Tools和IIS express中使用.
asp.net-mvc entity-framework windows-8 entity-framework-5 visual-studio-2012
有没有办法使用Entity Framework 5映射字典?
根据我在搜索时发现的情况,直到EF 4.1才支持它,不确定EF 5是否提供了任何创新方法来轻松映射.
我正在使用字典为类的每个对象存储"可变数量的属性".
如果不支持在这种情况下使用的最佳替代数据结构(由EF支持)?
我有一个asp.net mvc 3 Web应用程序,它具有实现系统相关EFcontexts和服务的插件程序集.
例如,我有一个看起来像下面这样的程序集:
System1Controller : IController // from System.Web.Mvc
ISystem1Service {
IList<System1Type> GetOperation(string something);
}
System1Service : ISystem1Service
{
private ISystem1Entities context;
public System1Service(ISystem1Entities context)
{
this.context = context;
}
}
ISystem1Entities
{
IDbSet<System1Type> Operations { get; set; }
}
System1Entities : DbContext, ISystem1Entities
Run Code Online (Sandbox Code Playgroud)
使用Unity Bootstrapper并调用Bootstrapper.Initialize()与以下BuildUnityContainer()实现一起使用
private static IUnityContainer BuildUnityContainer()
{
var theContainer = new UnityContainer();
var connectionString = ConfigurationManager.ConnectionStrings["WebAppConnectionString"];
if (connectionString == null)
{
throw new ApplicationException("The ConnectionString is not defined.");
}
// register all your components …Run Code Online (Sandbox Code Playgroud) .net asp.net-mvc dependency-injection unity-container entity-framework-5
我正在使用Entity Framework 5构建一个ASP.Net MVC4 Web应用程序.我不得不使用现有的sql server数据库,但也想使用Code First,所以我按照本教程http://msdn.microsoft.com/en-us /data/jj200620.aspx
我的应用程序使用Entity Framework自动迁移.
我在整个开发阶段使用的sql server版本是2008年,然而,在最后一刻我被告知数据库需要在sql server 2005上运行.我得到了我在sql server 2008设置中使用的数据库(确切的) sql server 2005上的表,属性名,关系等.但是,我的web配置等设置指向sql server 2005数据库,当我对我的一个模型类进行更改时,自动迁移不起作用.
我收到以下错误
数据库中已经有一个名为"tblcourseprofessionTarget"的对象.
有人可以帮忙吗?
谢谢.
如果我没有添加足够的信息,请道歉.
我在VS2012中的表单上有一个名为binding的bindingsource控件,并且有一个绑定到它的DateTimePicker控件。
对于绑定属性,我具有MinDate = 1/01/1753和MaxDate = 31/12/9998值是通过从压延机中选择“今天”设置的。2013年5月4日11:27 AM
我使用设置了绑定源
var dset = base.Context.ContactEvents;
var qry = dset.Where(p => p.Id > 0).OrderBy(x => x.Id);
qry.Load();
this.bindingSource.DataSource = dset.Local.ToBindingList();
Run Code Online (Sandbox Code Playgroud)
绑定源的使用方式如下:
public void RefreshBindingDataSourceAndPosition(BindingSource binding)
{
binding.DataSource = this.bindingSource.DataSource; // error raised here
binding.Position = this.bindingSource.Position;
}
Run Code Online (Sandbox Code Playgroud)
错误信息是
System.ArgumentOutOfRangeException越过了本机/托管边界HResult = -2146233086 Message =值'1/01/0001 12:00:00 AM'对'值'无效。“值”应介于“ MinDate”和“ MaxDate”之间。参数名称:值Source = System.Windows.Forms ParamName =值StackTrace:在System.Windows.Forms.DateTimePicker.set_Value(DateTime值)内部异常:
我可以通过不绑定数据选择器并将其设置在EventsBindingSource_CurrentChanged事件中来解决此问题。
但是,这样做似乎很奇怪。如何使数据绑定正常工作?
[更新]此问题与此处描述的问题类似, 我试图在一个较简单的项目中重现此问题,以便尝试找出原因,但是它在较简单的项目中有效。项目也可以在另一台计算机上工作。在同时使用SQL Server 2012和2008R2的计算机上会发生此问题。我尝试在控制面板中更改日期格式和国家/地区。我也尝试了format属性的不同设置。我也尝试将日期字段设置为支持null。
当我将错误复制到剪贴板时,它显示以下内容;
发生System.Reflection.TargetInvocationException HResult = -2146232828 Message = Exception已由调用目标抛出。Source = mscorlib StackTrace:位于System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object []参数,Object []参数)的System.RuntimeMethodHandle.InvokeMethod(对象目标,Object []参数,签名sig,布尔构造函数)InnerException: …
我试图在我的网站上使用基于实体框架代码的迁移.我目前有一个包含多个项目的解决方案.我想要初始化数据库的Web API项目和另一个名为DataLayer项目的项目.我已在DataLayer项目中启用了迁移并创建了一个初始迁移,我希望它将用于创建数据库(如果它不存在).
这是我启用迁移时获得的配置
public sealed class Configuration : DbMigrationsConfiguration<Harris.ResidentPortal.DataLayer.ResidentPortalContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(Harris.ResidentPortal.DataLayer.ResidentPortalContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person …Run Code Online (Sandbox Code Playgroud) 我已经开始在实体框架中使用CodeFirst方法.
运行我的代码时,我无法在DbContext - ProductsDb中对DbSets执行任何操作
我检查了连接字符串,我认为它是正确的但尝试执行操作会导致错误
参数源不能为null.
这是ProductsDb类
public class ProductsDb : DbContext
{
public ProductsDb(string connectionString) : base(connectionString)
{
}
public ProductsDb()
{
}
public DbSet<AProduct> AProducts;
public DbSet<BProduct> BProducts;
public DbSet<CProduct> CProducts;
public DbSet<DProduct> DProducts;
}
Run Code Online (Sandbox Code Playgroud)
连接字符串在app.config中定义如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ProductsDb" providerName="System.Data.SqlClient"
connectionString="Data Source=MyPC\DEV;Initial Catalog=Test;User ID=sa;
Password=pass;" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
抛出错误的代码是:
GetAProduct(string id)
{
AProduct aProduct = null;
using (ProductsDb productsDb = new ProductsDb())
{
aProduct = (from a in productsDb.AProducts
where a.Id== id
select …Run Code Online (Sandbox Code Playgroud) 我正在使用Entity Framework和Code First模型(宠物项目,我喜欢编辑简单的类并自动更新我的模式).我有一个类如下:
[Table("Polygons")]
public class Polygon
{
public int PolygonId { get; set; }
public String Texture { get; set; }
public virtual ICollection<Point> Points { get; set; }
}
[Table("Points")]
public class Point
{
public int PolygonId { get; set; }
public double X { get; set; }
public double Y { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
将多边形存储在数据库中并能够查询其纹理对我很有用.另一方面,如果我将一个带有5,000个点的多边形保存到数据库中,则需要永远运行那么多插入,老实说,除了检索单个多边形之外,我永远不会查询点.
我喜欢做的是摆脱"Point"类中的"PolygonId",摆脱"Points"表,让Polygon表看起来像
PolygonId int PK
Texture varchar(255)
Points XML
Run Code Online (Sandbox Code Playgroud)
然后将这些点序列化为一个直接保存到表中的字符串,然后将其反序列化为一个点数组.有没有办法让EF执行此操作,或者为字段编写自定义序列化器/反序列化器,所以至少在整个代码库中使用时它似乎是自动的?
谢谢,
担
在为我的代码优先EF 5上下文启用迁移后,由于迁移历史记录字符串被添加到项目的resx文件,我开始收到TON的CA1701和CA1703代码分析违规.
我不关心禁用CA1701和CA1703,也不想为每个要添加的迁移抑制100条消息.有没有办法将resx的xml文件或单个resx条目标记为// <自动生成/>以便停止发生?如果我必须禁用这两个规则,那么它只是希望这不是唯一合理的答案!
TIA杰森
CREATE OR REPLACE PACKAGE johns_test_pkg AS
PROCEDURE test(some_parameter IN NUMBER,
success_id OUT NUMBER);
PROCEDURE test_no_out_parameter(some_parameter IN NUMBER);
PROCEDURE test_no_in_parameter(success_id OUT NUMBER);
END johns_test_pkg;
/
CREATE OR REPLACE PACKAGE BODY johns_test_pkg AS
--
PROCEDURE test(some_parameter IN NUMBER,
success_id OUT NUMBER)
IS
v_app_user_session_id INTEGER;
BEGIN
v_app_user_session_id := 1 + some_parameter;
success_id := v_app_user_session_id;
END;
--
PROCEDURE test_no_out_parameter(some_parameter IN NUMBER)
IS
v_app_user_session_id INTEGER;
BEGIN
v_app_user_session_id := 1 + some_parameter;
END;
--
PROCEDURE test_no_in_parameter(success_id OUT NUMBER)
IS
v_app_user_session_id INTEGER;
BEGIN
v_app_user_session_id := 1 + …Run Code Online (Sandbox Code Playgroud) c# ×3
asp.net-mvc ×2
.net ×1
c#-4.0 ×1
code-first ×1
migration ×1
oracle ×1
resx ×1
sql-server ×1
windows-8 ×1