简体   繁体   中英

How to load database external library (assembly) from Entity Framework 6 Code-First?

I use EF.6 code-first, and my task is to load external library for SQL Server (Assembly). Assembly is provided as SQL script with binary for example:

CREATE ASSEMBLY [assembyName]
FROM 

0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300675910540000000000000000E00002210B010B000028000000060000000000005E46000000200000006000000000001000200000000200000400000000000000040000000000000000A0000000020000000000000300408500001000001000000000100000100000000000001000000000000000000000000C4600004F000000006000002003000000000000000000000000000000000000008000000C000000D44400001C000000000000000000000000000000000000....

And the assembly is creating properly if I execute the script from Management Studio.

So my question is... Is there a way to do it like good practice or should I read the file and use Database.SqlQuery<string> which I want to avoid? I hope there is a another good practice.

It's highly unusual to use SQL CLR in a code-first workflow. Do you really want to be managing this database schema through migrations? You can use SSMS or SSDT to manage the database schema and still use the code-first classes and mapping in EF.

If you did actually want to do this in your migrations, storing the TSQL script files and reading them when applying a migration seems like a sensible approach. Why do you want to avoid that?

Okay, I've just export the assembly to .sql create script file and include it in my .NET Project.That help to use SqlFile(filePath) method in EF migrations to create a assembly. Thank you David Browne for answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM