[Solved] how can create Unique Constraint with multi column with entityframework

In your EntityTypeConfiguration you can do something like this: Property(m => m.CompanyId) .HasColumnAnnotation(“Index”, new IndexAnnotation(new IndexAttribute(“IX_YourUniqueIndexName”, 1) { IsUnique = true })); Property(m => m.Code) .HasColumnAnnotation(“Index”, new IndexAnnotation(new IndexAttribute(“IX_YourUniqueIndexName”, 2) { IsUnique = true })); This will create a unique index on those 2 columns. Make sure you use the same name for the unique … Read more

[Solved] Where can I find the template files for project item templates I’ve added via Extension Manager in VS2010?

MSDN: During installation, Extension Manager uncompresses the .vsix file and puts its contents in %LocalAppData%\Microsoft\VisualStudio\10.0\Extensions\Company\Product\Version. Company, Product, and Version are specified in the extension.vsixmanifest file, and correspond to the namespace, project name, and version number that are set in the project properties. But strange, I also cannot find. I tried to install DbContextCSharp.vsix and find … Read more

[Solved] VB Net Class in C# [closed]

Need to make sure you’ve added the reference, as well as set the types you’re trying to access to public. Once this is done, you should make using references where appropriate, otherwise you’ll need to specify the entire namespace address each time you reference it. See Namespaces in Visual Basic and look over the code … Read more

[Solved] Why do I get Argument exception when I try to use “Include(“PropertyName”)” in query EF?

I solved the problem. Actually the problem was I didn’t have a using directive to System.Data.Entity namespace at the top of my class. Even thought I could use “Include(“PropertyName)” name in my query, I couldn’t use “Include(x=> x.Childs)”. But after adding “using System.Data.Entity” on top of my class I can use “Include” in these both … Read more

[Solved] Convert non-async Linq Extension method to Async [closed]

This is an XY problem. What you’re trying to achieve isn’t the same thing as what your question is asking. Your desired syntax wouldn’t work, even if you made this method async: var courses = await ids.ToChunks(1000) .Select(chunk => Courses.Where(c => chunk.Contains(c.CourseID))) .SelectMany(x => x).ToListAsync(); And the result you really want is just as easily … Read more

[Solved] how to get one value from a table in the entity framework

Let me give you some direction Do not use a propertie to get your data, use a method like this: //returns an enumeration of users filtered by the given expression Public IEnumerable<User> GetUsers(Expression<Func<User, bool>> expression) { return db.Users.Where(expression); } // returns the first occurency of a user filtered by the given expression Public User GetUser(Expression<Func<User, … Read more

[Solved] Why null is returned?

This shouldn’t be the case. from wp in context.WorkPanels select wp; is equivalent to context.WorkPanels.Select(wp => wp);. The MS implementations of Select (Enumerable.Select / Queryable.Select) never return null. There must be something else wrong somewhere else. 4 solved Why null is returned?

[Solved] Razor Page .NET Core 2.2 If + ElseIf statement doesn’t work in Lambda expression [duplicate]

I replaced this: .OrderBy(p => { if (p.Office == “President”) return 0; else if (p.Office == “Vice-President”) return 1; else if (p.Office == “Secretary-Treasurer”) return 2; }).ToListAsync(); with this: .OrderBy(p => p.Office == “President” ? 0 : p.Office == “Vice-President” ? 1 : p.Office == “Secretary-Treasurer” ? 2 : 3).ToListAsync(); I’m hoping it is useful … Read more

[Solved] why my query doesn’t work correctly? [closed]

i solved my problem,i was forgotten that i use the IsPostBack : if (!IsPostBack) { if (Request[“Id”] != null) { Int32 ID = Int32.Parse(Request[“Id”].ToString()); using (NoavaranModel.NoavaranEntities1 dbContext = new NoavaranModel.NoavaranEntities1()) { var query = (from list in dbContext.Packages where list.Id == ID select list).FirstOrDefault(); txtName.Text = query.Name; txtLevel.Text = query.Level; txtDescription.Text = query.Description; Image2.ImageUrl = … Read more