entity-framework-4

How to map many-to-many relationships in Entity Framework CTP5?

萝らか妹 提交于 2019-12-10 23:13:11
问题 I'm trying to map 2 types (user -> languages) using 3 tables (user - junction table - languages), and looks like the modelBuilder is expecting both types to have a reference to each other (like user.languagesSpoken, and language.UsersSpeaking). So basically I can build something like modelBuilder.Entity<User>().HasMany(x=>x.LanguagesSpoken).WithMany(x=>x.UsersSpeaking) . I don't need a reference from language to user, however - and can't figure out how to map that.. Also, is there a way to

LINQ to Entities instead of stored procedure?

南楼画角 提交于 2019-12-10 23:06:42
问题 I am using the Entity Framework to access my database and I just figured out that mapping stored procedures to methods using entity is a bit too complex and probably not well suited to do what I want exacltly. I am new to LINQ and I am wondering if I sould be better off just with ADO.NET. Here is the SQL code I need to translate: SELECT p.Player_id, p.Name, p.Position, SUM(s.Goals) AS goalsb, SUM(s.Assists) AS assistsb, SUM(s.Points) AS pointsb FROM Dim_Player AS p INNER JOIN Fact_Statistics

Multiplicity constraint violated. DB first EF 4.1

六月ゝ 毕业季﹏ 提交于 2019-12-10 22:25:35
问题 I have the following model: the i run the following to add a new user: using (var context = new CamelotDB()) { Console.WriteLine("Creating Test User"); DomainEntity userToAdd = new DomainEntity() { EntityName = "Test User", EntityType = DomainEntity.eEntityType.User, EntityCreationDate = DateTime.Now, EntityLastUpdateDate = DateTime.Now, EntityCreatorUserID = 0, Creator = context.DomainEntities.Find(0), EntityUpdaterUserID = 0, Updater = context.DomainEntities.Find(0), EntityParentID = null,

The property 'Id' is part of the object's key information and cannot be modified

早过忘川 提交于 2019-12-10 21:50:09
问题 I have a sample web app that I am writing and im confused why i'm getting this The property 'Id' is part of the object's key information and cannot be modified. when i'm not updating the 'Id'? Ok, so this is what I am trying to do. I have 2 tables Topics and Posts and -- User creates a new topic it should add a topic record on the database Get the topic Id and set that Id to the Post's TopicId Get that post's Id and set it as Topic's LastPostId I'm re updating the post so whenever I need to

Is it possible to include SqlFunctions.StringConvert in a Lambda Expression?

落花浮王杯 提交于 2019-12-10 21:05:28
问题 I have been learning Expressions and using the code below to add build up an expression against a database model (EF4 - ORACLE not SQL!) This works perfectly against Oracle, and allows me to dynamically build up predicates such as "CustomerId", "Contains", 2 into f=>f.CustomerId.ToString().ToLower().Contains("2") However, if I try against SQL Server then it fails because I need to call SqlFunctions.StringConvert - but I don't know how to get that included in the Lambda? My end result would be

Table-per-type inheritance insert problem

a 夏天 提交于 2019-12-10 21:03:14
问题 I followed this article on making a table-per-type inheritance model for my entities, but I get the following error when I try to add an instance of a subclass to the database. Here is how I create the subtype: var cust = db.Users.CreateObject<Customer>(); // Customer inherits User db.Users.AddObject(cust); db.SaveChanges(); I get the following error when I make that last call: "A value shared across entities or associations is generated in more than one location. Check that mapping does not

Entity Framework scalar function mapping

ぃ、小莉子 提交于 2019-12-10 20:35:50
问题 I have scalar function: CREATE FUNCTION [dbo].[CheckLocation] ( @locationId Int ) RETURNS bit AS BEGIN //code END I want to use it in Entity Framework context. I have added this in the *.edmx file: <Function Name="CheckLocation" ReturnType="bit" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" > <Parameter Name="locationId" Type="int" Mode="In" /> </Function> I have also created a partial class with

EF Table-per-hierarchy mapping

蹲街弑〆低调 提交于 2019-12-10 20:27:37
问题 In trying to normalize a database schema and mapping it in Entity Framework, I've found that there might end up being a bunch of lookup tables. They would end up only containing key and value pairs. I'd like to consolidate them into one table that basically has two columns "Key" and "Value". For example, I'd like to be able to get Addresses.AddressType and Person.Gender to both point to the same table, but ensure that the navigation properties only return the rows applicable to the

How to use Pivot table with Entity Framework?

旧城冷巷雨未停 提交于 2019-12-10 20:22:36
问题 I have a table something like this: I would like to use EF which will use a stored procedure which will return a unpivot result set back. But the problem is, how would I model it so that I can use it in RIA services to push the data to client. I was going for something like this public class RegionModel { public string Name { get; set; } public List<string> Quarter { get; set; } public List<int> Sales { get; set; } } Same way there will be a QuarterModel as well. Based on the user selection,

Reload object in an Entity Framework context with updated values

允我心安 提交于 2019-12-10 19:10:15
问题 I have an EF object that I pull from the db. I then make an update to the corresponding row in the DB through a function call which uses another DBContext . After this update, I would like to reload the contents of the object with the updated contents, however the EF context seems to cache the contents. Here's a sample of the code(I've removed some unrelated fluff to make it simpler): using (UmbrellaEntities context = new UmbrellaEntities()) { var umbrella = (from u in context.Umbrellas where