ef-code-first

Entity Framework RC1 DbContext query issue

我怕爱的太早我们不能终老 提交于 2019-12-06 09:39:01
I'm trying to implement the repository pattern using entity framework code first rc 1. The problem I am running into is with creating the DbContext. I have an ioc container resolving the IRepository and it has a contextprovider which just news up a new DbContext with a connection string in a windsor.config file. With linq2sql this part was no problem but EF seems to be choking. I'll describe the problem below with an example. I've pulled out the code to simplify things a bit so that is why you don't see any repository pattern stuff here. just sorta what is happening without all the extra code

EF: Database design issues regarding cross database relations

时光怂恿深爱的人放手 提交于 2019-12-06 09:22:46
Summary I am currently prototyping a (very straight-forward?) multi-tenant web-application where users (stored in database 1 ) can register to different tenants (stored in a database per tenant (same db schema). An architecture that I thought would apply to a lot of multi tenant solutions. Sadly, I found out that cross database relations are not supported in Entity Framework (I assumed it's still the case for EF6). I provided the links below. The next short sections explain my problem, and ultimately my question(s). The rational behind the design I choose to have separate databases; one for

How can I change the default max length of string properties in Entity Framework 6?

*爱你&永不变心* 提交于 2019-12-06 09:11:55
问题 By default convention, strings properties in an entity model that are not explicitly given a max length are set to nvarchar(max) in the database. We wish to override this convention and give strings a max length of nvarchar(100) if they are not already explicitly set otherwise. I discovered the PropertyMaxLengthConvention built-in convention, which by its description and documentation would seem to be what I am looking for. However, it either doesn't work or I'm using it wrong or it just

Entity Framework Code First Left Join

断了今生、忘了曾经 提交于 2019-12-06 08:52:43
问题 I've created a simple DB in EF code first but appear to have hit a problem. What I would like to do is, query the DBContext to retrieve a custom object CheckedTag that would have all of the available tags and a boolean field of checked. Code First abstracts the Many-To-Many table and I can't seem to find the correct query. I've tried var qry = from t in Db.Tags from a in Db.Articles where(a.Id == articleId) select new CheckedTag { Id = t.Id, Name = t.Name, PermanentUrl = t.PermanentUrl,

Reusing a GUID in EF Code First DatabaseIntializer

别等时光非礼了梦想. 提交于 2019-12-06 08:47:50
So I am trying to build Custom membership using EF. I dont really know what i am doing but it has gone fairly smooth so far. I am on the Database Initializer step where i am trying to dump data into the database soon as the project runs. My class Application.cs uses a GUID as a primary key as seen below. I am trying to figure out how i can add that GUID into the database. I don't know if this is possible but this is what i am trying to do. I took the default login's Database you get when you make a normal web application project in VS 2012 and trying to recreate that database using EF Code

Entity Framework one-to-zero-or-one foreign key association

时光毁灭记忆、已成空白 提交于 2019-12-06 07:26:48
I am in the process of changing the back-end of an existing application to use Entity Framework Code First. I've used the built-in tool in Visual Studio 2015 to generate POCO classes based on my existing database. This worked perfectly for the most part, except for two classes, with a one-to-zero-or-one relationship. These are my (simplified) classes: public class Login { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int TeamMemberId { get; set; } public virtual TeamMember TeamMember { get; set; } } public class TeamMember { [Key]

How to add computed column using migrations in code first?

邮差的信 提交于 2019-12-06 06:21:20
I have added this computed column inside my data model [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string FullName { get; private set; } After that I created it inside my database using this query ALTER TABLE [MyDataBase].[dbo].[User] ADD FullName as ([FirstName] + ' ' + [LastName]) When I run my code I get an error that my database has changed . My question How to create migration for this computed column (because it's already created using sql query) Entity Framework doesn't know how to properly handle migrations for computed columns, so you need to help it out. Firstly,

EF Code first 4.3 naming convention foreign key

夙愿已清 提交于 2019-12-06 06:12:26
I have the following entity: public class User { public int ID {get; set;} public int GroupID {get; set;} // navigation property with public Group Group {get; set;} // foreign key field public Adress Adress {get; set;} // navigation property only } The table generated from entity framework looks like: ID GroupID Adress_ID I don't like, that the column naming for the FK columns is not the same. Can I achieve that both use the same convention either "GroupID, AdressID" or "Group_ID, Adress_ID"? I use convention over configuration and don't want to use Fluent API. EF 4.1 to 4.3 doesn't support

Incorrect usage of spatial/fulltext/hash index and explicit index order EF

。_饼干妹妹 提交于 2019-12-06 05:54:07
I am getting Incorrect usage of spatial/fulltext/hash index and explicit index order this error while trying to login. I am not using Entity Framework migration. [DbConfigurationType(typeof(MySqlEFConfiguration))] public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { } static ApplicationDbContext() { // Set the database intializer which is run once during application start // This seeds the database with admin user credentials and admin role Database.SetInitializer<ApplicationDbContext>(new CreateDatabaseIfNotExists

Entity Framework 4.1 Code First - Should many relationship ICollections be initialised

馋奶兔 提交于 2019-12-06 05:52:43
问题 In Entity Framework 4.1 when creating a POCO, should the class be coded to initialise the Many relationships or is there some reason to allow the Entity Framework to have control over these properties? public class Portfolio { private ICollection<Visit> _visits; public virtual ICollection<Visit> Visits { get { if (_visits == null) { _visits = new List<Visit>(); } return _visits; } set { _visits = value; } } } Or public class Portfolio { public virtual ICollection<Visit> Visits { get; set; } }