entity-framework

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

半世苍凉 提交于 2021-02-15 07:34:16
问题 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 = ""

Cross Join in Entity framework Lambda Expressions

半城伤御伤魂 提交于 2021-02-15 06:58:02
问题 How can I do the following join in EF? Tables have no relation with each other, no foreign keys. Select t1.ID, t1.firstname, t2.ID,t2.name from MY_TEST_TABLE1 t1, MY_TEST_TABLE2 t2 where t1.firstname = t2.name 回答1: You could do this: var query= from t1 in context.MY_TEST_TABLE1 from t2 in context.MY_TEST_TABLE2 where t1.firstname == t2.name select new { Table1Id= t1.ID, FirstName= t1.firstname, Table2Id=t2.ID,Name= t2.name}; Another way to do a cross join in Linq to Entities is using

Unable to create an object of type 'DatabaseContext'. For the different patterns supported at design time error

夙愿已清 提交于 2021-02-11 15:15:40
问题 I'm using sqlserver2017 in docker in ubuntu os create asp.netcore 3 web app error in run dotnet ef add migrations firstmigrate Unable to create an object of type 'DatabaseContext'. For the different patterns supported at design time, 回答1: Had similar problem after adding own DbContext constructor with (2) parameters. App was ok, but migrations stopped working. Your looks similar - in case you do not need DatabaseContext constructor, try to remove it ... There is a build and DI running behind

How can I use a collection on the data item row of my Windows Community Template datagrid as the Itemsource for a ComboBox column on the same row?

随声附和 提交于 2021-02-11 14:56:33
问题 How can I bind the ItemsSource of a Combobox column to a collection that is a sub-property of a property on the same row? In other words, the DataGrid is bound to a collection of items of a class the contains Property1 and Property2. So the DataGrid has two columns, Property1 and Property2. Property1 has a sub-property that is an Observable Collection. The column for Property2 is a Combobox column that should use Property1's Observable Collection as its ItemsSource. I'm loading the grid's

Zero-or-one relationship in EF Core

て烟熏妆下的殇ゞ 提交于 2021-02-11 14:21:49
问题 I have a somewhat special scenario of a Zero-or-one relationship in EF Core which cannot be easily modeled by the default (as described, e.g.,in EF Core One to One or Zero Relationship). I've got multiple entities with a 0-1 relationship to a "Match" entity. Multiple instances can reference the same "Match" entity (which is why I can't put the foreign key into the "Match" table, which seems to be the recommended way of modeling a 0-1 relationship). How to define the relationship from one of

Zero-or-one relationship in EF Core

混江龙づ霸主 提交于 2021-02-11 14:20:09
问题 I have a somewhat special scenario of a Zero-or-one relationship in EF Core which cannot be easily modeled by the default (as described, e.g.,in EF Core One to One or Zero Relationship). I've got multiple entities with a 0-1 relationship to a "Match" entity. Multiple instances can reference the same "Match" entity (which is why I can't put the foreign key into the "Match" table, which seems to be the recommended way of modeling a 0-1 relationship). How to define the relationship from one of

EF Core LINQ query failing due to limitation?

孤人 提交于 2021-02-11 13:52:45
问题 I am trying to do quite a simple group by, and sum, with EF Core 3.0 However am getting a strange error: System.InvalidOperationException: 'Processing of the LINQ expression 'AsQueryable((Unhandled parameter: y).TransactionLines)' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. var creditBalances = await context.Transaction .Include(x => x.TransactionLines) .Include(x=>x.CreditAccount) .Where(x => x.CreditAccount.UserAccount.Id ==

How to make a CREATE view & controller method for a model that has a list field?

偶尔善良 提交于 2021-02-11 13:50:09
问题 I have these 2 models: public class Invoice { public string InvoiceID {get; set; } public List<InvoiceElement> InvoiceElements {get; set;} [...other fields...] } public class InvoiceElement { public string InvoiceElementID {get; set; } [ForeignKey("Invoice")] public string InvoiceID { get; set; } public virtual Invoice Invoice { get; set; } public string Item {get; set;} [...other fields...] } I am unable to make a CREATE view for new Invoices that lets me add InvoiceElements . I want to have

Entity Framework 6 - Attaching a graph of entities queried with AsNoTracking

我的未来我决定 提交于 2021-02-11 13:47:06
问题 I am retrieving a list of entities from a table FattureFornitori , and loading also a collection owned by them (Voci, plural form - Voce, singular form) and a reference from each Voce to a TipoCosto entity: var db = new DbGestPre(); db.Configuration.ProxyCreationEnabled = false; var s = db.FattureFornitori .Include(x => x.Voci) .Include(x => x.Voci.Select(y => y.TipoCosto)) .AsNoTracking().ToList(); Now, multiple Voci within a single FattureFornitori can reference the same TipoCosto . So,

How to implement pagedList on DbQuery Entity in Dbcontext without fetching full data in .net core?

独自空忆成欢 提交于 2021-02-11 12:49:06
问题 I have to execute a sql string in .net core so first I added a Dbquery type entity in dbcontext. internal DbQuery<TempData> MyDataList{ get; set; } Then I fetched the data with my sql string as var data = context.MyDataList.FromSql(dataqueryString).ToList(); Iam getting the data correct but need to implement PagedList on this without fetching the whole data from database. I have tried like var data = context.MyDataList.FromSql(dataqueryString).ToPagedList(1,10) But this will fetch whole data