entity-framework-4

ASP.NET MVC3 - Data Annotations with EF Database First (ObjectContext, DbContext)

て烟熏妆下的殇ゞ 提交于 2019-12-18 04:52:19
问题 How can we use Data Annotations for models if the models are generated with 4.1 ADO.NET DbContext Generator or something else? 回答1: You can use a partial metadata class 来源: https://stackoverflow.com/questions/5956081/asp-net-mvc3-data-annotations-with-ef-database-first-objectcontext-dbcontext

ASP.NET MVC3 - Data Annotations with EF Database First (ObjectContext, DbContext)

坚强是说给别人听的谎言 提交于 2019-12-18 04:52:06
问题 How can we use Data Annotations for models if the models are generated with 4.1 ADO.NET DbContext Generator or something else? 回答1: You can use a partial metadata class 来源: https://stackoverflow.com/questions/5956081/asp-net-mvc3-data-annotations-with-ef-database-first-objectcontext-dbcontext

Finding Entity Framework contexts

泄露秘密 提交于 2019-12-18 04:36:09
问题 Through various questions I have asked here and other forums, I have come to the conclusion that I have no idea what I'm doing when it comes to the generated entity context objects in Entity Framework. As background, I have a ton of experience using LLBLGen Pro, and Entity Framework is about three weeks old to me. Lets say I have a context called "myContext". There is a table/entity called Employee in my model, so I now have a myContext.Employees. I assume this to mean that this property

EntityFramework - Where is the connection string?

China☆狼群 提交于 2019-12-18 04:31:40
问题 I've deleted the connection string from my web.config and Entity Framework is still connecting to the database! Where is the connection string being set? This is an issue because I need to make the live version of my website point to the live database. 回答1: Here's a gotcha I found with the "convention over configuration" philosophy when it comes to trying to connect to existing databases (like you're doing). If your DbContext class (e.g. Northwind) is in a namespace (e.g. MvcProject), for

LINQ to Entities does not recognize the method

纵然是瞬间 提交于 2019-12-18 04:16:08
问题 I am following this article on MSDN. I ported it to EF Code First. public interface IUnitOfWork { IRepository<Employee> Employees { get; } IRepository<TimeCard> TimeCards { get; } void Commit(); } public class HrContext : DbContext { public DbSet<Employee> Employees { get; set; } public DbSet<TimeCard> TimeCards { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Employee>() .HasMany(e => e.TimeCards) .WithOptional(tc => tc.Employee); } }

Simple way to compare Dates in DateTime attribute using Entity Framework 4 and Linq queries

前提是你 提交于 2019-12-18 04:12:08
问题 I'm trying to run the following bit of code, but the comparison fails by not handing my the entities I expect it to. It's comparing 06/09/2011 0:00:00 to 06/09/2011 12:25:00 , the latter being my databases record value. So that's why the comparison is failing and I'm not getting the records I need. I'm just trying to compare if the dates match up, I'm don't care about the time. DateTime today = DateTime.Now.Date; var newAuctionsResults = repo.FindAllAuctions() .Where(a => a.IsActive == true |

Simple way to compare Dates in DateTime attribute using Entity Framework 4 and Linq queries

末鹿安然 提交于 2019-12-18 04:12:07
问题 I'm trying to run the following bit of code, but the comparison fails by not handing my the entities I expect it to. It's comparing 06/09/2011 0:00:00 to 06/09/2011 12:25:00 , the latter being my databases record value. So that's why the comparison is failing and I'm not getting the records I need. I'm just trying to compare if the dates match up, I'm don't care about the time. DateTime today = DateTime.Now.Date; var newAuctionsResults = repo.FindAllAuctions() .Where(a => a.IsActive == true |

How to specify SQL Server XML data type in Entity Frameworks 4.0 Model?

我与影子孤独终老i 提交于 2019-12-18 04:04:08
问题 I'm building an ORM using Entity Frameworks 4.0 (CTP5) in the Model-First pattern. A few of my entities have complex (object tree) properties that don't need to be ORM entities - they're only of interest to back-end server systems that use this database, not to the clients that use this database. I could just serialize the property's object tree down to a string and store it in the DB as a string, but the SQL Server XML data type is really appealing. To be able to query over the XML data

Clean way to deal with circular references in EF?

核能气质少年 提交于 2019-12-18 03:55:22
问题 Say I have this table structure: Client ----------- ClientId int not null (identity) CurrentDemographicId int null (FK to ClientDemographic) OtherClientFields varchar(100) null ClientDemographic ------------------ ClientDemographicId int not null (identity) ClientId int not null (FK to Client) OtherClientDemographicFields varchar(100) null The idea is that Client (in EF) will have a ClientDemographics list and a CurrentDemographic property. The problem is when I setup the object structure and

How to use SQL wildcards in LINQ to Entity Framework

谁说胖子不能爱 提交于 2019-12-18 03:42:06
问题 I have a query that looks like this: IQueryable<Profile> profiles = from p in connection.Profiles where profile.Email.Contains(txtSearch) select p; I know that when this is converted to SQL it uses a LIKE '%<value of txtSearch>%' but if txtSearch = "jon%gmail.com" it converts it to `LIKE '%jon~%gmail.com%'. The ~ escapes the % in the middle that is a wild card. How do I get around that? I need to be able to put wild cards into my LINQ to EF searches. 回答1: I'm not sure that this is possible