entity-framework

access two models in a IEnumerable view

霸气de小男生 提交于 2020-01-06 05:48:07
问题 I'm trying to access a two models in one view, basically i have two models User Model namespace SLMDemo0.Models { using System; using System.Collections.Generic; public partial class User { public int UID { get; set; } public string UserName { get; set; } public int PID { get; set; } public int LID { get; set; } public string SK { get; set; } public string Brand { get; set; } public string CN { get; set; } public string SN { get; set; } public string AT { get; set; } public string Ref { get;

WCF, Entity Framework 4.1 and Entity's State

☆樱花仙子☆ 提交于 2020-01-06 05:39:06
问题 I am developing an application which will expose WCF services. I am using Entity Framework 4.1 at the DAL. The problem is when I load some entity (let say a Customer that has Order which in turn has OrderDetail). After loading it I make some changes in Customer, Order and OrderDetail objects (some new orders are added and some existing orders are removed/updated) and send the object graph to WCF service to update it as following. Customer oCustomer; using(var context = new MyContext) /

Entity Framework generic entity inheritance id error

旧城冷巷雨未停 提交于 2020-01-06 05:08:32
问题 Part 2 problem, which continues from here: EntityFramework Core - Update record fails with DbUpdateConcurrencyException Error: The derived type 'BinaryFile' cannot have KeyAttribute on property 'Id' since primary key can only be declared on the root type. I am trying to make inheritance for my entities as much as possible, so I remove duplication as much as possible. My inheritance structure: public interface IEntityMinimum { bool IsDeleted { get; set; } byte[] Version { get; set; } string

Chosen as the deadlock victim on simple Add() -> SaveChanges()

笑着哭i 提交于 2020-01-06 04:51:12
问题 This simple program private static void Main(string[] args) { Parallel.For(0, 1000000, InsertTestEntity); } private static void InsertTestEntity(int i) { using (var dbContext = new TestDbContext()) { dbContext.TestEntities.Add(new TestEntity { HugeString = "Baby shark," + string.Join(", ", Enumerable.Repeat("doo", 500)) }); dbContext.SaveChanges(); } } public class TestEntity { [Key] public int Id { get; set; } public string HugeString { get; set; } } public class TestDbContext : DbContext {

Entity framework with oracle database

会有一股神秘感。 提交于 2020-01-06 04:39:04
问题 I'm using entity framework with oracle database. I downloaded the provider from http://oracleef.codeplex.com/. Today I converted my project to work with VS2010. Is there a way (free) to work with oracle db using VS2010? Thanks! 回答1: Try express editions of some data providers. For example, http://www.devart.com/dotconnect/oracle/... 回答2: Well Visual Studio (and Windows) both require paying Microsoft, so "No, you can't do it for free". You can use Oracle XE (Express Edition) for free though.

Using extension method in Linq to Entities

烂漫一生 提交于 2020-01-06 04:30:10
问题 Code: public static IEnumerable<TableRowModel> GetRows() { var to_ret = db.TableRows.select(x=> new TableRowModel(){ TableRowId = x.TableRowId, Type = x.Type, Name = x.Name, CreatedAt = x.CreatedAt, ModifiedAt = x.ModifiedAt, Enums = x.Enums.Select(y => y.ToEnumModel()), }); return to_ret; } public static EnumModel ToEnumModel(this Enum x) { var to_ret = new EnumModel() { CFPId = x.CFPId, CreatedAt = x.CreatedAt, ModifiedAt = x.ModifiedAt, }; return to_ret; } I get the following error when

How to select data with linq after filter parameters are determined

让人想犯罪 __ 提交于 2020-01-06 04:19:35
问题 I have a report in which the user can select different filters to apply to a dataset. At design time, I don't know what filters the user will apply, so I grab the whole dataset. For instance, if the user wants to see contacts that live in Chicago, I first grab all contacts... IList<contact> contacts = db.contacts.ToList(); then I check the form collection for filters and apply them... contacts = contacts.Where(t => t.state == form["state"]).ToList(); The issue is that getting all contacts to

How to use SQL's LIKE on a guid in Entity Framework?

China☆狼群 提交于 2020-01-06 04:17:47
问题 In SQL Server, uniqueidentifier columns can be used like strings with the LIKE comparison: SELECT * FROM dbo.Table WHERE GuidColumn LIKE '4c38e01e%' How can I use this feature in Entity Framework? I want something like this context.Table.Where(x => x.StringColumn.Contains("some string")) but for a Guid column instead for string columns: context.Table.Where(x => x.GuidColumn ???? "4c38e01e") 回答1: As far as I know there is no way to convert Guid to string on the fly in EntityFramework. I'm

C# How To Update Entity Model Connection String

烈酒焚心 提交于 2020-01-06 03:53:07
问题 This is my first WinForm application using the Entity Framework and I have to be able to update the connection string for the entity model I created on the fly and in my app.config file I have the following connectionString: <add name="NCIPEntities" connectionString="metadata=res://*/NCIPModel.csdl|res://*/NCIPModel.ssdl|res://*/NCIPModel.msl;provider=System.Data.SQLite;provider connection string='data source="C:\Test\NCIP\NCIP.db3";pooling=True'" providerName="System.Data.EntityClient" />

2 foreign keys in one table using entity framework

人走茶凉 提交于 2020-01-06 03:20:08
问题 I have three classes Event, Dog, Result Each dog can participate in many events and for each event he will get a score related to this specifik event. Thus must mean that my result-class must contain 2 foreign keys. 1 that specifies the event and 1 that specifies the dog. I am very confused about how to set this up. I´ve been getting som help with this earlier and I hope someonen can help me again: Here are my classes now: public class Dog { public int DogId { get; set; } public string Name {