entity-framework-4

multiple “1 to 0..1” relationship models

[亡魂溺海] 提交于 2019-12-08 09:31:11
问题 I am using this tutorial from microsoft to create a one-zero-to-one relationship with EF4.1 Between an Instructor and OfficeAssignment. This is working like a charm. But now I want to add a Home for each Instructor (1 to zero-or-1) like in this: I added the Home model exactly the same way as the OfficeAssignment (like in the tutorial above), but when I try to add controllers for these model, I get the error "An item with the same name has already been added". So my model is set up incorrectly

Can't use ToString() in LINQ to Entities query

梦想与她 提交于 2019-12-08 09:23:54
问题 So I have the following code: string searchQuery = collection["query"]; var srmas = ( from SRMAs in db.SRMAs join SRMAStatus in db.SRMAStatus on SRMAs.Id equals SRMAStatus.Id join PurchaseOrders in db.PurchaseOrders on SRMAs.PONumber equals PurchaseOrders.PONumber join Suppliers in db.Suppliers on PurchaseOrders.SupplierID equals Suppliers.SupplierID join SRMADetails in db.SRMADetails on SRMAs.Id equals SRMADetails.SRMAId where ids.Contains(SRMAs.Status) && ( searchQuery.Contains

How to attach additional action performed on create / update or when changes in table are detected? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-08 08:30:48
问题 This question already has answers here : DBContext Added/Attached Event? (3 answers) Closed 6 years ago . I am using Entity Framework and when I insert or update Row in Table I would like to perform additional action. Not only stored procedure from database but actual function in code - preferably event based. (asynchronous execution) Both scenarios should trigger sending some message to a handler or in other way enable execution of a function. 1) create var Row = DbContext.Table.GetById(Id);

How to Clone POCO entity and add to context

拜拜、爱过 提交于 2019-12-08 07:39:18
问题 I am using EF4 and I have create POCO objects with proxies from my database structure . I have a POCO (object) which has lots of relationships to other entities. I created a deep copy of the object using DataContractSerializer and BinaryFormatter and lets call it clonedObject. function used for cloning is: public T CloneProxy<T>(T source) { var dcs = new System.Runtime.Serialization .DataContractSerializer(typeof(T)); string filePath = "Initiative.txt"; using (FileStream file = new FileStream

Table per hierarchy inheritance with POCO entities in Entity Framework 4

巧了我就是萌 提交于 2019-12-08 07:28:33
问题 Our organization is looking to standardize on Entity Framework once v4 comes out. As a result, I am looking at what it would take to migrate our application that uses NHibernate for persistence to EF4 using POCO support. In a couple of places we use single table inheritance (also known as Table Per Hierarchy). I have been unable to get it to work using the following. Payment (base class [should be abstract but having trouble there as well]) CreditCardPayment (concrete implementation)

define scalar function with ef4.1 code first?

血红的双手。 提交于 2019-12-08 07:12:45
问题 i have a function called distancebetween i wnat to define it in scalar valued function to call it by linq if there is away to do that by EF4.1 code first ? 回答1: No. Code first was designed as "code first" = you will create a code and it will create a database where no database logic exists (no views, stored procedures, triggers or functions). Because of that it is completely missing features for mapping database logic like functions and stored procedures. If you want to use it in LINQ you

Using LINQ and Entity how do I return values of a many-to-many relationship

不打扰是莪最后的温柔 提交于 2019-12-08 07:08:42
问题 I have two entities, Account and Subscription with a many-to-many association between them. I can't seem to find in the tutorials anywhere how to do the following: I want to find all the Accounts with a Subscription of type x. If I wasn't using the Entity framework I could join to the AccountSubscription table, but that isn't accessible via Entity. Do I have to create a special entity if I need to query on a many-to-many relationship? 回答1: EF should create a navigation property for a many-to

Is there an Update Object holder on Entity Framework?

对着背影说爱祢 提交于 2019-12-08 06:14:51
问题 I'm currently inserting/updating fields like this (if there's a better way, please say so - we're always learning) public void UpdateChallengeAnswers(List<ChallengeAnswerInfo> model, Decimal field_id, Decimal loggedUserId) { JK_ChallengeAnswers o; foreach (ChallengeAnswerInfo a in model) { o = this.FindChallengeAnswerById(a.ChallengeAnswerId); if (o == null) o = new JK_ChallengeAnswers(); o.answer = FilterString(a.Answer); o.correct = a.Correct; o.link_text = ""; o.link_url = ""; o.position =

What is the best implementation for changing the database schema at runtime using Entity Framework 4?

两盒软妹~` 提交于 2019-12-08 05:43:51
问题 We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the "single database, separate schema" model discussed, among other places, here and here, where each tenant has one or more users and is split out with its own, tenant specific, SQL Server schema. The application is using Entity Framework 4. In order for users for different tenants to access the data in their schema, we need to be able to specify a schema when creating an entity's ObjectContext. I have seen a few

Full text + spatial search with Entity Framework 4

落花浮王杯 提交于 2019-12-08 05:42:16
问题 Let's say I have a SQL 2005 database with a table called Restaurants. The Restaurants table has the following columns: RestaurantId Name Latitude Longitude I want to let users search for restaurants by name and/or address. How do I write the LINQ query to support this? I need to be able to support the possibility that the user doesn't enter in a name or address, just the name, just the address, or both name and address. My initial idea was to write a stored procedure to calculate the distance