【c#-EF核心实体类型】教程文章相关的互联网学习教程文章

c#-EntityType’是变量,但在使用反射时就像类型一样使用【代码】

我需要在DbContext中注册所有实体. 我创建一个扩展以自动注册带有反射的所有实体:public static void RegisterAllEntity<BaseType>(this DbModelBuilder builder, params Assembly[] assmblies){IEnumerable<Type> types = assmblies.SelectMany(x => x.GetExportedTypes()).Where(x => x.IsClass && !x.IsAbstract && x.IsPublic && typeof(BaseType).IsAssignableFrom(x));foreach (Type EntityType in types)builder.Entity<En...

c#-传递引用参数与包装类型的详细列表【代码】

我需要从一个函数中获取三个对象,我的本能是创建一个新类型来返回三个引用.或者如果ref是相同的类型,我可以使用数组.但是,通过引用比较容易:private void Mutate_AddNode_GetGenes(ref NeuronGene newNeuronGene, ref ConnectionGene newConnectionGene1, ref ConnectionGene newConnectionGene2){}显然这没有什么错,但是我不愿使用这种方法,主要是出于美学和心理偏见的考虑.实际上,是否有充分的理由使用其中一种方法来替代其他方...

c#-用于xaml中的通用类型的TypeConverter【代码】

我正在研究初始化XAML中声明的泛型类型的成员.这是针对WPF 4和将来的Silverlight中的(reduced) generics support. (我已经在VS2010 Beta 2中使用x:TypeArguments和XamlReader.Load尝试了以下方案,但为简单起见,将使用TestClassInt32:TestClass< int> {},因为它的行为与直接使用泛型类型相同,但更容易今天使用已编译的xaml进行测试.) 这是我正在使用的测试类型.public class TestClass<T> {[TypeConverter( typeof(StringListToIt...

C#反射,将MakeGenericMethod与具有’new()’类型约束的方法一起使用【代码】

我试图按如下方式使用MethodInfo MakeGenericMethod:foreach (var type in types){object output = null;var method = typeof (ContentTypeResolver).GetMethod("TryConstruct");var genmethod = method.MakeGenericMethod(type);var arr = new object[] { from, output };if ((bool)genmethod.Invoke(null, arr))return (IThingy)arr[1];}针对以下通用方法:public static bool TryConstruct<T>(string from, out IThingy result...

c#-类型已经包含“ Zehut”的定义【代码】

该问题存在于我的editme.aspx页面中.Error 1 The type 'editme' already contains a definition for 'Zehut' C:\Documents and Settings\Itay.ITAYB-5A14B8105\My Documents\Visual Studio 2008\WebSites\WebSite2\editme.aspx.cs 110 20 C:\...\WebSite2Error 3 Ambiguity between 'editme.Zehut' and 'editme.Zehut(object, System.Web.UI.WebControls.ServerValidateEventArgs)' C:\Documents and Settings\Itay.ITAYB-5A14B810...

从接口类型的对象设置实现接口的类的所有成员,而无需使用C#编写大量代码【代码】

这听起来可能有点复杂,但是我会尽力解释清楚. 如果我的接口较长,是否可以在C#中使用:public interface IInterface {bool interface_1;bool interface_2;bool interface_3;bool interface_4;bool interface_5;... }和一个实现接口的类public class MyClass : IInterface {... }想象一下,我有一个IInterface myInterface对象,有没有一种方法可以创建MyClass对象myClass并使用myInterface之一设置myClass的所有字段,而无需一一设置所...

c#-从泛型类型确定类型派生【代码】

我有以下实用程序例程,用于确定类型是否从特定类型派生:private static bool DerivesFrom(Type rType, Type rDerivedType) {while ((rType != null) && ((rType != rDerivedType)))rType = rType.BaseType;return (rType == rDerivedType); }(实际上,我不知道是否有更方便的方法来测试派生…) 问题是我想确定一个类型是否派生自一个泛型类型,但是没有指定泛型参数. 例如,我可以写:DerivesFrom(typeof(ClassA), typeof(MyGenericC...

c#-存储html CSS JavaScript的最佳数据类型

美好的一天. 我有一个PHP&以MySql为背景,而我只是从ASP.NET开始.我没有ASP的任何背景,只有C#的经验. 好吧,我的问题非常简单,我希望能够将HTML,CSS和Javascript代码直接保存到MS SQL Server数据库中. 但是我不知道哪种数据类型更适合存储代码,请记住我想保持原始代码的格式(断行,格式等). 任何帮助表示赞赏. 环境详细信息: > Windows 7(x86)> Visual Studio 2010旗舰版> SQL Server 2008年> ASP.NET和C#> NET Framework 4.0 谢谢.解...

c#-创建具有不同数据类型的集合并绑定到列表【代码】

我正在尝试创建具有不同数据类型的集合以绑定到Silverlight和C#中的列表框控件. 如果每种数据类型都实现一个接口,是否可能? 例如,我有单独的对象“ Violin”,“ Guitar”和“ Drums”,每个对象都实现了“ IMusicalInstrument”接口.然后可以创建列表,将其绑定到列表框,或者将“ Violin”,“ Guitar”和“ Drums”对象添加到该列表吗?解决方法:是的,您可以使用列表Generic来查看List<T>.您可以使用一些工具创建一个列表,如下所示:...

c# – 方法的类型签名在调用DLL方法时不兼容PInvoke【代码】

我有一个带接口的DLLstruct modeegPackage {uint8_t version; // = 2uint8_t count; // packet counter. Increases by 1 each packetuint16_t data[6]; // 10-bit sample (= 0 - 1023) in big endian (Motorola) formatuint8_t switches; // State of PD5 to PD2, in bits 3 to 0 };__declspec(dllexport) void __cdecl initSerial();__declspec(dllexport) void __cdecl closeSerialPort();__declspe...

C#-------浮点数据类型【代码】

c++数据类型大小受操作平台的影响,而在c#中,数据类型的定义都以与平台无关的方式定义,以备将来C#和.NET迁移到其他平台上。 这里说一下浮点类型在c#语言中的定义。 c#可以支持float ,double和decimal浮点数据类型。 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 7 namespace ConsoleApplication18 {9 class Program 10 { 11 ...

C#中自定义返回类型【代码】

在项目中会用到AjaxResult的返回值,根据自己的需要进行自定义,如下参考:using System; using System.Collections.Generic; using System.Linq; using System.Web;namespace ToolsUse.CommonHelper {public class AjaxResult{/// <summary>/// 是否产生错误/// </summary>public bool IsError { get; set; }/// <summary>/// 错误信息,或者成功信息/// </summary>public string Message { get; set; }/// <summary>/// 成功可能...

C#------值类型与引用类型【代码】

定义:值类型直接存储其值,存储在堆栈中; 引用类型存储对值的引用,存储在托管堆中。例子: 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 7 namespace ConsoleApplication18 {9 class Program 10 { 11 class Vector 12 { 13 public int value; 14 } 15 static void Main(string[] args) ...

Java的BigDecimal是与C#的Decimal相对应的最接近的数据类型吗?

根据图表here,Java到C#的Decimal中的等效数据类型是BigDecimal. 这真的是这样吗?怎么了“大”序言?在Java中似乎没有“SmallDecimal”或“LittleDecimal”(更不用说“MediumSizedDecimal”). 不过,我必须说,这张图表是我在这个主题上发现的最清楚的东西;在暴风雨之后,其他链接here和here以及here对我来说就像密西西比河一样清晰.解决方法:是的 – 这是相应的类型. 因为你在C#之后使用Java – 不要太惊讶于发现这样的细微差别 – ...

工控随笔_C#连接PLC_之_C#入门_03_基本数据类型【代码】

using System; using System.Collections.Generic; using System.Linq; using System.Text;//namespace 关键字用来定义命名空间,命名空间主要用来解决命名冲突的问题 //命名空间还有一个作用是将一组相关的类组织到一个抽象空间里面,必须引用 //命名空间,才能访问命名空间的内容 namespace ConsoleApplication1 {class Program{static void Main(string[] args){//C#内置了很多简单数据类型,也可以称为基本数据类型//主要分为...