在许多OutOfMemoryExceptions之后,我运行内存分析器.System.LocalDataStoreElement [] cunsumes 123 GB的内存.初始化后应用程序消耗70 MB.处理完一些数据后,内存分配为700 MB(即使在几次GC.Collect()调用之后).我使用Code-First Entity Framework 4.1 Update 1.这个内存分配对于Code-First是否常见?
我正在使用Entity Code First创建一个数据库和表来存储用户,角色和UserRoles.
我的课程如下 -
public class User
{
public int UserId { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
public class Role
{
public int RoleId { get; set; }
public string Rolename { get; set; }
}
public class UserRole
{
public int UserRoleId { get; set; }
public int UserId { get; set; }
public int RoleId { get; set; }
public virtual User User { …Run Code Online (Sandbox Code Playgroud) 我一直是一个面向数据库的程序员,所以直到今天,我总是使用数据库驱动的编程方法,我对T-SQL和SQL Server非常有信心.
我试图围绕Entity Framework 6 代码优先的方法 - 坦率地说 - 我正在努力.
我有一个现有的数据库 - 所以我做了一个Add New Item > ADO.NET Entity Data Model > Code-First from Database,我得到了一堆代表我现有数据库的C#类.到现在为止还挺好.
我现在要做的是探索如何处理正在进行的数据库升级 - 包括模式以及"静态"(预先填充的)查找数据.我的第一个抱怨是,从数据库进行逆向工程的实体正在使用Fluent API进行配置,而我似乎更自然地创建了我想要创建的具有数据注释的C#类的新表."混合"这两种方法是否有任何问题/问题?或者,我可以告诉逆向工程步骤只使用数据注释属性而不是Fluent API吗?
我的第二个甚至更大的抱怨:我正在尝试创建漂亮的小型迁移 - 每个我想要添加的功能集(例如新表,新索引,一些新列等) - 但是似乎我不能只有一个"挂起"的迁移......当我有一个,并且我进一步修改我的模型类,并且我尝试使用第二次迁移时add-migration (name of migration),我受到了欢迎:
无法生成显式迁移,因为以下显式迁移尚未处理:[201510061539107_CreateTableMdsForecast].在尝试生成新的显式迁移之前应用挂起的显式迁移.
说真的?!?!?我不能有多个,单个挂起的迁移?我需要update-database 在我添加的每一次微小迁移后运行?
似乎是一个相当大的缺点!我宁愿创建我的10个,20个小型,紧凑,易于理解的迁移,然后一举应用它们 - 无法做到这一点!?!?这真的很难相信.....任何方式?
我正在尝试制作一个非常简单的实体框架代码优先项目,但无法解决“调用目标已抛出异常”的问题。当我试图从我的数据库中检索数据时。
我有一个独特的课程:
public class TestStylo
{
[Key]
public int TestStyloID { get; set; }
StyloType styloType { get; set; }
public string name;
public TestStylo(StyloType styloType, string name)
{
this.styloType = styloType;
this.name = name;
}
public StyloType getTypeStylo{
get { return styloType; }
}
}
public enum StyloType
{
pen,
wood,
gold
}
Run Code Online (Sandbox Code Playgroud)
我的模型是:
public class Model1 : DbContext
{
public Model1()
: base("name=Model1")
{
}
public DbSet<TestStylo> MyStylos { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的 App.Config 是:
<configuration>
<configSections> …Run Code Online (Sandbox Code Playgroud) 在我的 EF 代码优先 MVC 应用程序中,我正在播种一个超级用户基本数据。稍后,可以从应用程序界面更改它的值。
但是我面临的问题 - 每次运行应用程序时,此种子数据都会刷新。我不想要这个重置。有什么办法可以避免这种情况吗?
//This is my DatabaseContext.cs -
public partial class DatabaseContext : DbContext
{
public DatabaseContext() : base("name=EntityConnection")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DatabaseContext, Migrations.Configuration>());
}
}
//This is my Configuration.cs-
internal sealed class Configuration : DbMigrationsConfiguration<DatabaseContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = false;
}
protected override void Seed(DatabaseContext context)
{
User user = new User()
{
UserId = 1,
EmailAddress = "xyz@abc.com",
LoginPassword = "123",
CurrentBalance = 0,
};
context.Users.AddOrUpdate(user);
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下实体:
public class Notification
{
public int Id { get; set; }
public string Title { get; set; }
public Guid RefId { get; set; }
public Object Ref { get; set; } // << The navigation property: Sometime its type is Poll and sometime is Test, maybe I add other types too
public NotifTypes Type { get; set; }
}
public enum NotifTypes
{
Poll=1,
Test=2,
// Other NotifTypes here
}
//-------------------------------------------------------------------
public class Test
{
public int Id …Run Code Online (Sandbox Code Playgroud) 我创建了一个名为“类别”的简单表。每个类别可以有一个或多个子类别,也可以没有类别。
我无法在 ASP.NET 5 中使用 EF core Code-First 来完成此操作。您介意帮我完成此表吗?
public int Id {get;set;}
public string Title {get;set;}
public int? parentId {get;set;}
Run Code Online (Sandbox Code Playgroud)
关系如何设置?
我正在尝试通过转换我拥有的Web表单应用程序来学习asp.net MVC.这是一个房间预订应用程序,其中有一个客户表(tblCustomerBooking)与tblRental有一对多的关系 - 所以一个客户可以预订多个房间.彼此匹配的字段是tblCustomerBooking.customer_id - > tblRental.customer_ref
我正在尝试首先使用代码 - 并构建一个模型类 - 但我无法弄清楚如何链接这两个表,因此当我查询dbContext时,它将返回一个客户,其中有一个或多个租用同一型号.
我的表定义是:
CREATE TABLE [dbo].[tblCustomerBooking](
[customer_id] [bigint] IDENTITY(1,1) NOT NULL,
[room_id] [bigint] NULL,
[customer_name] [varchar](110) NULL,
[customer_email] [varchar](50) NULL
CONSTRAINT [PK_tblCustomerBooking] PRIMARY KEY CLUSTERED
(
[customer_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[tblRental](
[rental_id] [bigint] IDENTITY(1,1) NOT NULL,
[room_id] [bigint] NOT NULL,
[check_in] [datetime] NOT NULL,
[check_out] [datetime] NOT …Run Code Online (Sandbox Code Playgroud) 如何首先使用代码将EF 5.0与成员资格提供程序集成?
我有自己的数据库架构,我想用它来注册用户等.
membership-provider code-first asp.net-mvc-4 entity-framework-5 simplemembership
这是基于Programming Code First EF的示例.
请看下面的课程.当PersonRepository调用实例化时,调用InsertOrUpdate方法返回Null值.据我所知,IQuariable的FitstOrDefault不应该返回Null.
这里有什么问题.谢谢您的帮助
public class Person
{
public int PersonId { get; set; }
public int SocialSecurityNumber { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
//public int MyProperty { get; set; }
public List<Lodging> PrimaryContactFor { get; set; }
public List<Lodging> SecondaryContactFor { get; set; }
public PersonPhoto Photo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
照片类
public class PersonPhoto
{
public int PersonID { get; set; }
public …Run Code Online (Sandbox Code Playgroud) .net entity-framework code-first ef-code-first entity-framework-5