partial-classes

c# auto generated partial class redefine property get set

北战南征 提交于 2019-12-13 00:43:30
问题 I'm moving from mainly classic asp to .NET. So this may be a stupid question, but I can't find an answer. I have an MVC App using Database First and Entity Framework. Now I would like to add some logic to the auto generated 'partial' classes. From what I have read it should be a matter of creating a new partial class with the same namespace and name. But when I do that I get an error "(This member is defined more than once)" and "Ambiguity between [partial class] and [partial class]". I

Using “partial” on a generic class

亡梦爱人 提交于 2019-12-12 11:35:12
问题 Hey guys, I'm using a generic class called ViewModelCollection<BaseViewModel> which handles a lists of ViewModels and delivers standard add() and delete() commands. Now I'm wondering if I can "extend" this class using the partial construct for a certain ViewModel, whose name is, say, CarViewModel . Is something like this possible? partial class ViewModelCollection<BaseViewModel> { ... some command and list stuff ... } partial class ViewModelCollection<CarViewModel> { ... special commands for

How to make user control partial classes aware of controls declared in the base class?

假装没事ソ 提交于 2019-12-12 10:49:53
问题 Do we have to do something special to have ASP.NET partial classes aware of controls that are declared in our user control's base classes? The partial classes keep generating declarations for controls in the base class which mean the controls in the base class get hidden and are null. 回答1: The CodeFileBaseClass attribute can be applied to @Page or @Control declarations to make the ASP.NET runtime aware of any controls declared in your base class. MSDN describes it as follows: Specifies the

Using partial classes

纵然是瞬间 提交于 2019-12-12 10:37:08
问题 Is there any overhead using partial classes in case of memory, performance etc? If we create a partial class can we identify whether the class was partial or not using reflector ?? 回答1: No. They are compiled to the same IL as if they weren't partial. It's a purely compile-time thing - the CLR doesn't even know that they were ever partial. Note that with partial methods introduced into C# 3, the method doesn't even get emitted in the IL unless it's implemented in one of the files. Both the

Problem with DataAnnotations in partial class

三世轮回 提交于 2019-12-12 09:09:04
问题 So in my mvc project's Project.Repository I have [MetadataType(typeof(FalalaMetadata))] public partial class Falala { public string Name { get; set; } public string Age { get; set; } internal sealed class FalalaMetadata { [Required(ErrorMessage="Falala requires name.")] public string Name { get; set; } [Required(ErrorMessage = "Falala requires age.")] public string Age { get; set; } } } I use Falala as a model in my Project.Web.AccountControllers, and use a method to get violations.

Entity Framework - how do I use the entity relationships in my extended classes?

青春壹個敷衍的年華 提交于 2019-12-11 07:38:50
问题 I am trying to extend the partial classes that the entity framework creates so that I can more easily work with objects like in the code below (please let me know if there's a better or more exceptable way of doing this with the entity framework) Public Sub New(ByVal ProjectID As Integer) Dim proj As Project = (From p In db.Project.Include("Status") Where p.ProjectID = ProjectID).First _ProjectID = proj.ProjectID _ProjectName = proj.ProjectName Me.Status.StatusID = proj.Status.StatusID 'I get

Entity Framework: Extending partial class with interface without touching the EF-generated classes

点点圈 提交于 2019-12-11 03:43:18
问题 My problem is similar to this post: Interface inheritance in Entity Framework Thus, I copy that example and modify it for my issue: public interface IBaseEntity { DateTime CreatedOn { get; set; } string CreatedBy { get; set; } } // The following two classes are generated by Entity Framework public partial class SomeEntity { public int SomeEntityId { get; } public string Name { get; set; } public DateTime CreatedOn { get; set; } public string CreatedBy { get; set; } } public partial class

Properties in partial class not appearing in Data Sources window!

随声附和 提交于 2019-12-10 19:13:41
问题 Entity Framework has created the required partial classes. I can add these partial classes to the Data Sources window and the properties display as expected. However, if I extend any of the classes in a separate source file these properties do not appear in the Data Sources window even after a build and refresh. All properties in partial classes across source files work as expected in the Data Sources window except when the partial class has been created with EF. EDIT: After removing the

Placement of extended partial classes in entity framework

混江龙づ霸主 提交于 2019-12-10 14:32:17
问题 Since partial classes have to be in the same namespace is my only option to place them in the same directy as my .edmx? If this is the case I am assuming the file name always has to be different. Also, is there anything additional that I have to do or do I just create another partial class with the same name in the same directory and add properties/methods to it? 回答1: The partial classes should be in the same project as the .edmx-file. (the same directory is not required). Say your Entity

Event Handler located in different class than MainWindow

不羁岁月 提交于 2019-12-10 14:12:25
问题 So I followed the guide on the following site to restrict the characters a textbox can accept. http://www.rhyous.com/2010/06/18/how-to-limit-or-prevent-characters-in-a-textbox-in-csharp/ My problem is I can't figure out how to make the event handler trigger in the secondary class. Basically how do I tell VS to look for the event handler code in that class instead of MainWindow? I tried searching, but apparently don't know the correct terms to use. The xaml reference I used was xmlns:DigitBox=