entity-framework-4

ASP.net MVC3 DropDownListFor int Required DataAnnotation

本秂侑毒 提交于 2019-12-25 09:36:35
问题 Is there a way to trigger client-side validation for the select list created by DropDownListFor? The select list that gets created by the helper doesn't seem to get the "data-val" or "data-val-required" attributes that text inputs get for client-side validation. The validation does occur on the server-side when I check ModelState.IsValid, and the validation message is then displayed on the subsequent page load. I set a default option of "Please Select..." on the list because I want the user

Why POCO Classes generated EF 4.x DbContext Generator for C# are Partial?

a 夏天 提交于 2019-12-25 07:40:51
问题 I'm using EF 4.3.1 and " EF 4.x DbContext Generator for C# " for creating POCO using T4 . the classes generated are: namespace MyProjects.Models { public partial class ReCategory ... Why the class is PARTIAL? POCO are not classes without the plumbing of EF? If you think this question is not appropriate please comment I will remove it, thanks for your time. 回答1: Why shouldn't they be? Just about every code generator these days will generate partial classes, so that you can add your own members

The SqlParameter is already contained by another SqlParameterCollection

﹥>﹥吖頭↗ 提交于 2019-12-25 07:35:48
问题 I'm using EF DbContext SqlQuery to get a list of paged objects using PagedList (https://github.com/TroyGoode/PagedList) and I'm getting the following error: "The SqlParameter is already contained by another SqlParameterCollection" Here's my repository code: var db = (DbContext)DataContext; const string sqlString = @" WITH UserFollowerList AS ( SELECT uf.FollowId FROM UserFollow uf WHERE uf.UserId = @UserId ) SELECT * FROM UserFollowerList uf INNER JOIN [User] u ON uf.FollowId = u.UserId WHERE

Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Linq.IQueryable<AnonymousType#2>'

时间秒杀一切 提交于 2019-12-25 07:15:24
问题 This query is being compiled without errors: var _entityList = context.customer .Join(context.applications, cust => cust.cust_id, app => app.cust_id, (cust, app) => new { customer = cust, application = app }) .Join(context.advices, cust => cust.application.app_id, sa => sa.app_id, (cust, sa) => new { customer = cust, advice = sa }) .GroupBy(g => new { g.customer.customer.cust_id, g.customer.customer.cust_code, g.customer.customer.cust_name }) .Select(g => new { cust_id = g.Key.cust_id, cust

Proper implementation of an Identifying relationship in Entity Framework?

时间秒杀一切 提交于 2019-12-25 06:47:28
问题 Let's say I have an entity Author which has a name can write 0 .. 1 .. or many of the entity Book . The Book must be written by one Author , and it is not meaningful to talk of a Book with no Author . This (I believe) would be classified as an identifying relationship. With the EntityTypeConfiguration , would the following be the correct way of implementing this identifying relationship? public BookMapping() { HasRequired(book => book.Author) .WithMany(author => author.Books) .HasForeignKey

Entity Framework 4 CTP 5 POCO - Many-to-many or Lookup table?

喜你入骨 提交于 2019-12-25 04:44:16
问题 I'm building a personal blog app with Entity Framework 4 CTP 5 POCO only, where a Post can have many Tags and a Tag can be in many Posts . My question is whether to build a many-to-many model, or to have a lookup table. At first I was trying to use many-to-many, but I don't know how to do insertion, each time a new post is posted (with many tags selected), I'm not sure what to do so that the tags should be associated with the post (and wouldn't insert a new tag if the tag name already exists.

Why does L2E choke when I try to use an interface in my Where clause?

喜欢而已 提交于 2019-12-25 04:21:45
问题 I have a LINQ to Entities query (using EF 4) that has some pretty complicated set-based filtering going on. The code compiles just fine, but when I try to run it, I get the following error: Unable to create a constant value of type 'ITextEntity'. Only primitive types ('such as Int32, String, and Guid') are supported in this context. Now for the code. I have an interface that looks like this: public interface ITextEntity { int ID { get; set; } string TextValue { get; set; } EntityCollection

Entity framework and n-layered application

牧云@^-^@ 提交于 2019-12-25 04:05:25
问题 so, I have this: Web App Business Logic Data Access Logic I created in the data access logic, the entities, the context, the initializer. SO usually the higher layers, call the lower layer functionality, right? If I want to save a customer, I want to create a Customer entity from the web app. What I dont like is having a direct reference from the web app layer to the data access logic layer (class library) any idea? 回答1: This is how i did it on a previous project 4 Projects under my Solution

Entity and mapping using Entity Framework 4 how to handle null (ICollection)?

纵饮孤独 提交于 2019-12-25 03:21:04
问题 I have this fellowing entity : public class Post { public long PostId { get; private set; } public DateTime date { get; set; } [Required] public string Subject { get; set; } public User User { get; set; } public Category Category { get; set; } [Required] public string Body { get; set; } public virtual ICollection<Tag> Tags { get; private set; } public Post() { Category = new Category(); } public void AttachTag(string name, User user) { if (Tags.Count(x => x.Name == name) == 0) Tags.Add(new

Confusion over MVC and entity model

本小妞迷上赌 提交于 2019-12-25 03:13:28
问题 My confusion stems from the fact I am using 2 different walkthroughs on building mvc applications, namely: Steven Sanderson's pro asp.net mvc and the online mvc music store. The former creates a domain model, placing the entity model in there along with repositories, while the music store demo places the entity model in the mvc model folder. Which of these is the best approach. Should the entity model and associated repositories exist in a separate domain layer, or in the MVCs model folder.