entity-framework-4

Create a string collection from CheckedListBox.CheckedItems using LINQ

Deadly 提交于 2019-12-13 04:39:28
问题 I have used the Entity framework to populate a checked list box. I want to get the names of the checked items as a string collection so that they can then be used as a filter for another LINQ query. I populate the list box like this... _eventTypesCheckedList.DataSource = this._dataContext.tblEventTypes.OrderBy(ev => ev.EventTypeName); _eventTypesCheckedList.DisplayMember = "EventTypeName"; This is how I'm failing to get the string collection... var types = from eType in ((

Replace T-SQL triggers with Entity Framework 4.0 code?

雨燕双飞 提交于 2019-12-13 04:17:02
问题 Entity Framework 4.0 project. I am currently doing my cascading deletes using an INSTEAD OF DELETE trigger. Is there a way to just do this in my Data Model code? I thought about adding my Data Context class via partial class. Then using ObjectStateManager.ObjectStateManagerChanged to watch for deletes, and then delete children first. The problem is that will partial I can't hook into constructor to make sure my event gets hooked up. I guess I could make a factory method that created the

Can't insert data to with EF with Master-detail relationship

送分小仙女□ 提交于 2019-12-13 03:51:50
问题 Suppose I have 2 tables: Person(pid, ....) //Pid is identify colum as primary key Student(pid, Student_No,...) //pid is foreign key from Person, pid is a primary key too. Then use EF to generate entity model. THen try to insert new data with following code: Person person = new Person() { FirstName = "FirstName", LastName= "LastName", ... }; Student student = new Student(){Student_No="001", ...}; Student.Person = person; mycontext.Students.AddObject(student); mycontext.SaveChanges(); Then I

Entity Framework Complex LINQ Support

蹲街弑〆低调 提交于 2019-12-13 03:48:25
问题 I know that Entity Framework has some LINQ support problems (at least in comparison to its predecessor LINQ to SQL)...and usually I'm able to find a creative way of restructuring my LINQ query so that it's supported by EF and doesn't throw a "Unable to create a constant value of type ..." But this time I'm having trouble. As usual, the problem is related to complex joins. This time it's required for modeling some legacy data I'm working with. I have a query for Offices (a simple POCO) public

entity framework 4, code-only, relationships

寵の児 提交于 2019-12-13 03:39:30
问题 I can't figure out how to solve the following problem. What i need it a relationship from one base class to another, so that every derived class has a relationship with the same table, called 'Item' in my example. Since this is just an example it doesn't reflect my program. In the real program the relationship with class Item is in a different namespace. Therefore it can't be in the derived class. The error: A key is registered for the derived type 'WebApplication1.Client'. Keys must be

Map a Stored Procedure to Entity Framework with MergeOption

妖精的绣舞 提交于 2019-12-13 03:19:10
问题 Is there a way to map a stored procedure to Entity Framework in such a way that the ExecuteFunction uses the MergeOption parameter with the NoTracking option? 回答1: You could update the T4 template file to add "MergeOption.NoTracking" as the 2nd parameters. Then just R-Click on the .edmx and select "Run Custom Tool". This is a quick workaround but I would also like to know a more long term solution. If this is the only solution, can the default T4 templates be updated so that this is automatic

LINQ generates incorrect SQL (reference to a non-existent table)

☆樱花仙子☆ 提交于 2019-12-13 02:58:47
问题 MVC3 project, using LINQ to Entity, and Entity Framework 4 Code-First. In another post ( Return products which belong to all tags in a list using LINQ ), I received assistance in creating a LINQ statement to return a subset of data. The LINQ is syntactically correct and compiles, but generates incorrect SQL. Specifically, it makes reference to a non-existent table. If I correct the table name, it returns the correct data, so the LINQ seems to be correct. Note in the interest of keeping this

EF4 - Is there any way it can be made to support unique indexes

心已入冬 提交于 2019-12-13 02:49:10
问题 My primary key is a guid column and I would like to have a unique index on another column in the table. I read that EF4 doesn't do anything for unique indexes. My question is: Can I add to a partial class any code that would allow me to check for non-unique values before my data hits the database. Currently I'm using the following configuration: Users Desktop <> wpf Datagrid <> Observable Collection <> EF4 <> SqlCe database. Thanks in advance. Richard 回答1: I don't think it can do this,

“Or” Together Expression<Func<EntityFramework Entity, bool>> in .NET 4, Silverlight RIA domain service

余生颓废 提交于 2019-12-13 02:37:38
问题 I have a small custom object defined as: public class TimeSeriesDefinition { public int classID; public DateTime startTime; public DateTime endTime; } I'm passing a List classIDs, a List startTimes, and a List endTimes into an RIA Domain Service function. As a matter of organization, I was grouping these values into a List of TimeSeriesDefinitions and then trying to use a foreach loop to create an expression that would select with AND operators between the values in a class and OR operators

EF DbContext.Set<T> filtered record only

自古美人都是妖i 提交于 2019-12-13 02:36:06
问题 I'm new to EF so be bit gentle right now I'm using 4.2 I just want to know what is the best way where I can restrict EF to load only filtered data instead of pulling all the data from the db and then applying filters over it. I can see DbContext.Set() or DbContext.Set().AsQueryable(); not sure about "Where" function but it seems to be working on same principle i.e already loads all the data for any given table and then applies filters over them wouldn't this be a major performance hit? Or am