entity-framework

EF Core Many-to-Many self join

北慕城南 提交于 2021-02-16 21:03:38
问题 I am trying to describe a many-to-many self-referential relationship to Entity Framework Core 2. Essentially what I'm trying to model is a sort of tree structure, in which each element can have an arbitrary number of parent and child elements (so I guess more a graph than a tree). Here's what I have so far: public class OrgLevel { ... public ICollection<OrgLevelOrgLevels> OrgLevelOrgLevelsAsParent { get; set; } public ICollection<OrgLevelOrgLevels> OrgLevelOrgLevelsAsChild { get; set; }

Using EF DbContext with mysql and sql in the same project

ぐ巨炮叔叔 提交于 2021-02-16 15:23:56
问题 I'm working on an ASP.net MVC project using EF in combination with MySql. Now this works just fine on its own but I also want to reference another class library that uses EF with SQL. When I reference the library EF seems to get confused on what provider to use for each DbContext. On my MySql DbContext I have the following attribute in order to tell EF this DbContext should be handled by the MySql provider: [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] Now on the SQL

Using EF DbContext with mysql and sql in the same project

我们两清 提交于 2021-02-16 15:23:47
问题 I'm working on an ASP.net MVC project using EF in combination with MySql. Now this works just fine on its own but I also want to reference another class library that uses EF with SQL. When I reference the library EF seems to get confused on what provider to use for each DbContext. On my MySql DbContext I have the following attribute in order to tell EF this DbContext should be handled by the MySql provider: [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] Now on the SQL

Constructor Initialization in Entity framework

大憨熊 提交于 2021-02-16 14:42:05
问题 I want to know the difference between those two codes can't understand what should I initialize the property in the constructor: Code 1: public class Student { public Student() { this.Courses = new HashSet<Course>(); } public int StudentId { get; set; } [Required] public string StudentName { get; set; } public virtual ICollection<Course> Courses { get; set; } } public class Course { public Course() { this.Students = new HashSet<Student>(); } public int CourseId { get; set; } public string

Render a Partial View in _layout.cshtml using the partialview model instance with DBContext dependency injection

瘦欲@ 提交于 2021-02-16 13:37:04
问题 At first I'd like to say I'm new to Asp.net Core and also with concepts of dependency injection (DI). I'm reading a lot trying understand it, so I ask for patience. I'm trying Razor Pages (not MVC) and my goal is to render to "_layout.cshtml" a partial view, in which information obtained using the Entity Framework is available on all pages. I added the DBContext in the Startup.cs file as follows: services.AddDbContext <AppDBContext> (options => options.UseSqlServer (Configuration

How To Scaffold a View Model in MVC 5

蓝咒 提交于 2021-02-16 04:54:09
问题 I'm trying to work on a simple application. I have three SQL tables brought in through Entity Framework and had the models created automatically. I want to be able to scaffold out the Create/Details/Edit etc. views automatically in Visual Studio. I can do this automatically when I scaffold from a single model (like Name alone), but can't get anywhere when using a View Model as a source. Here are my models Name public partial class Name { public Name() { this.Addresses = new HashSet<Address>()

How To Scaffold a View Model in MVC 5

随声附和 提交于 2021-02-16 04:53:31
问题 I'm trying to work on a simple application. I have three SQL tables brought in through Entity Framework and had the models created automatically. I want to be able to scaffold out the Create/Details/Edit etc. views automatically in Visual Studio. I can do this automatically when I scaffold from a single model (like Name alone), but can't get anywhere when using a View Model as a source. Here are my models Name public partial class Name { public Name() { this.Addresses = new HashSet<Address>()

Have model contain field without adding it to the database? [closed]

孤者浪人 提交于 2021-02-16 04:09:35
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 7 years ago . Improve this question In my Asp.NET MVC4 application I want to add a field to my model without adding it to the database. Sort of a field that only lives in c# instances of the model but not in the database itself. Is there any annotation or other way to exclude the field from the database itself?

Does EF Core 3.1 support DB First approach?

混江龙づ霸主 提交于 2021-02-16 04:01:10
问题 We are porting an ASP.NET MVC 4.x application to ASP.NET Core 3.1 . The current application is using EF 6.x DB first approach. As a part of this migration we are going to use EF Core 3.1 as an alternative to the current EF 6.x . So the question is: Does EF Core 3.1 support DB First approach? If not, what are the options? Are we left with only code first approach? Appreciate your helps. 回答1: Yes. It supports DB First Approach since .NET Core 1.0 until now. You need to download 4 from nugets

How to set multiple services from Entity Framework Core on Repository Pattern?

孤街浪徒 提交于 2021-02-15 07:34:59
问题 I am trying to build a structure using repository pattern in entity framework core. I have an generic interface and a service for general operations. They simply do CRUD transactions. My interface: public interface IGeneralService<TEntity> where TEntity : class { void Delete(TEntity entityToDelete); void Delete(object id); IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = ""