linq - Best approach for many-to-many relationship in Entity Framework code-first

I've been re-examining the way I'm using entities and I need advice.I'm creating a yoga booking service and each user will have a profile, spaces to meet up for yoga and events, with a date and time, for each space to meet up.So my relationships look like this and they are all one-to-manyYogaProfile -> YogaSpace(s) -> YogaSpaceEvent(s)When an event gets created, members (YogaProfiles) can join anyone's event. Kind of like a class. It's a registering/scheduling system. Initially I created a table called RegisterdStudents and added the coll...Read more

entity framework - Foreign Key Object Missing in LINQ GroupBy?

I am using GroupBy in my LINQ queries. My query is working fine, except my foreign key objects are missing. Then, I tried to add Include in my query. Following is my code:public ActionResult GetEmployees(){ var Emloyees = db.Employees.AsQueryable(); Emloyees.GroupBy(e=> new {e.JobTitleId, e.GenderId}) .Select(tr => new MyObject SalaryTotal = tr.Sum(r=>r.Salary) }).Include(tr=>tr.JobTitle).Include(tr=>tr.Gender).ToList();}I am getting this exception: The result type of the query is...Read more

entity framework - EF and dynamic table names

I am checking if there is way to dynamically change the table mapped to an Entity in EF 6. The schema of the table doesn't change, just the name. For example, I have an Entity called Orders, then I need to assign this Entity to a SQL view dynamically created when the program runs. The name of the view is generated in run-time, so I need to map that view name to the Orders entity in run-time. Any idea how to do this?Thanks in advance.-Fernando...Read more

entity framework - AutoMapping Stored Procedure Results

I'm wondering if there is any way to map a stored procedure result into into a class. this is what I have://DbContext Class:public DbSet<StoreProcedureModelResult> SPMR { get; set; }//Service Class:var result = ctx.Set<StoreProcedureModelResult>().FromSql("getXXXX p1 = {0},1).ToList();This works well, however, I'm using DataBaseMigrations and everytime I add one this thing creates StoreProcedureModelResult as a Table...I tried to ignore it onModelCreating, modelBuilder.Ignore<SPModels.test>();but this brings an exception:"Cann...Read more

inheritance - Fluent NHibernate Create entity mapping for overlapping entities

For eg. I have two tables in my database NonResidentStudents - columns studentID, studentname, ModeOfTransportResidentStudents - columns studentID, studentname, DateOfJoiningHostelstudentID and studentName are common columns and the last column is uncommon between the twoFor some reason, I cant change these tables or define a common master table and make uncommon columns in sub tables. So the table stucture is rigid.Now when trying to create an entity and mapping for the above schema using FLUENT NHIBERNATE (only) I would like to know if I can ...Read more

Adding core data records to Entity based on Relationships

I have two entities ProductModel and OrderItem. ProductModel has relationship set prodToOrder, inverse orderToProd and one to Many. OrderItem has relationship set with orderToProd with inverse prodToOrder and Many to one.I have added ProductModel data with out issues but my problem is after i inserted new records to OrderItem then go back and fetch the OrderItem, the product name is null. If i insert both records to ProductModel and OrderItem at the same time it will work but i do not added both entities as the same time i need to pick already ...Read more

entity framework - ASP.NET MVC 2.0 Implementation of searching in jqgrid

Hi I am trying to use the single column search in jqgrid using MVC 2 IN .NET (VS 2008) this is the code I have so far but I need an example to match it with or a tip of what I am missing jQuery("#list").jqGrid({ url: '/Home/DynamicGridData/', datatype: 'json', mtype: 'POST', search: true, filters: { "groupOp":"AND", "rules": [ {"field":"Message","op":"eq","data":"True"} ] }, multipleSearch: false, colNames: [ 'column1', 'column2'], colModel: [ { name: 'column1', index: 'column1'...Read more

entity framework - how to merge entities of same type if spaCy shows multiple entities due to ',' '\n' or 'any other reason'

I have to extract organization name from company letters. When extracting entities, due to ',' or '\n' or 'sometimes for other reason' it splits the organization name. spacy_data = nlp(text)spacy_data.ents if ent.label_ in =='ORG' expected output: capital international partners viactual output: capital international partners vi It showing as two different organizations. I want my final output to be capital_international_partners_vi so that I can use it further for creating one-word vector...Read more

entity framework - Mocking or faking DbEntityEntry or creating a new DbEntityEntry

Following on the heels of my other question about mocking DbContext.Set I've got another question about mocking EF Code First.I now have a method for my update that looks like:if (entity == null) throw new ArgumentNullException("entity");Context.GetIDbSet<T>().Attach(entity);Context.Entry(entity).State = EntityState.Modified;Context.CommitChanges();return entity;Context is an interface of my own DbContext.The problem I'm running in to is, how do I handle theContext.Entry(entity).State.I've stepped through this code and it works when I ...Read more

entity framework - EF connection string as DbContext constructor argument

I have seen some code sample that put an entity framework connection string as a constructor argument when creating a new DbContext. But when I added a new ADO.NET entity data model into a project (database first), the DbContext only has one parameterless constructor.Did I miss a step? What should I do to get that constructor?Visual Studio 2012 targeting .net framework 4.5 entity framework 5....Read more

Entity Framework 5: How to Outer Join Table Valued Function

I'm attempting to outer join a table with an inline table valued function in my LINQ query, but I get a query compilation error at runtime:"The query attempted to call 'OuterApply' over a nested query, but 'OuterApply' did not have the appropriate keys."My linq statement looks like this: var testQuery = (from accountBase in ViewContext.AccountBases join advisorConcatRaw in ViewContext.UFN_AccountAdvisorsConcatenated_Get() on accountBase.AccountId equals advisorConcatRaw.AccountId into a...Read more

How to make updatable DataGridView of joined Entity Framework tables using Linq query

I want to use a DataGridView to display and update data from two joined MSSQL tables, but I can't work out how to show the data I want and make it updatable.In this case, I want to display a bill of materials for a particular machine type ("HX" in the code below). 'Parts' are unique machine components (so contain the stock level, part drawing etc.) whereas 'Items' are 'instances' of a part in a particular context or assembly within a machine, so contain quantity, description etc. for that use.From the DB/model point of view these tables have a ...Read more